Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: Delete and restrict user #21

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions contract/Database.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ contract Database{
mapping( string => Details) private aadharToUser;
mapping( address => Details) private list;
uint256 private count=0;
mapping (string => bool) public added;
mapping( string => bool ) public added;
mapping( address => bool ) public restrictedUser;
mapping( string => address ) public aadharToAddress;

address public admin;
bool alreadyset=false;

Expand All @@ -25,8 +28,9 @@ contract Database{
}



modifier personPresent{
require(keccak256(abi.encodePacked(list[msg.sender].aadharId)) != keccak256(abi.encodePacked("")), "Person doesn't exist");
require(keccak256(abi.encodePacked(list[msg.sender].aadharId)) != keccak256(abi.encodePacked("")), "User doesn't exist");
_;
}
modifier Added (string memory aadhar)
Expand All @@ -35,6 +39,7 @@ contract Database{
_;
}


modifier onlyOnce()
{
require(!alreadyset,"Admin is already set");
Expand All @@ -47,6 +52,11 @@ contract Database{
_;
}

modifier isNotRestricted(){
require(!restrictedUser[msg.sender], "User is restricted");
_;
}

function set_Admin( address _admin) public onlyOnce()
{
admin=_admin;
Expand All @@ -58,23 +68,24 @@ contract Database{
admin=newadmin;
}

function getAdress()external view returns(address){
function getAddress()external view returns(address){
return msg.sender;
}


function addPerson(string memory aadharId,string memory name, string memory DOB, string memory phoneNo, string memory rollNo, string memory batchNo) public Added (aadharId)

function addPerson(string memory aadharId,string memory name, string memory DOB, string memory phoneNo, string memory rollNo, string memory batchNo) public Added (aadharId) isNotRestricted
{
require(bytes(list[msg.sender].aadharId).length == 0, "User already exists");
Details memory person = Details({aadharId: aadharId,name: name,DOB: DOB,phoneNo: phoneNo, rollNo: rollNo, batchNo: batchNo});
list[msg.sender]=person;
added[aadharId] = true;
aadharToAddress[aadharId] = msg.sender;
aadharToUser[aadharId] = person;
added[aadharId]=true;
count++;
}

function updateDetails(string memory aadharId,string memory name, string memory DOB, string memory phoneNo, string memory rollNo, string memory batchNo)public personPresent{
function updateDetails(string memory aadharId,string memory name, string memory DOB, string memory phoneNo, string memory rollNo, string memory batchNo)public personPresent isNotRestricted {
Details storage person = list[msg.sender];
person.aadharId = aadharId;
person.name = name;
Expand All @@ -85,18 +96,33 @@ contract Database{
added[aadharId]=true;

}
function checkDetails()public personPresent view returns(string[6] memory){
function checkDetails()public personPresent view personPresent returns(string[6] memory){
Details memory person = list[msg.sender];
string[6] memory details = [person.aadharId, person.name, person.DOB, person.phoneNo, person.rollNo, person.batchNo];
return details;
}

function findByAadhaarId(string memory _aadharId)public view onlyAdmin returns(string[6] memory){
require((bytes(aadharToUser[_aadharId].aadharId).length > 0), "Not found");
require((bytes(aadharToUser[_aadharId].aadharId).length > 0), "User not found");
Details memory person = aadharToUser[_aadharId];
string[6] memory details = [person.aadharId, person.name, person.DOB, person.phoneNo, person.rollNo, person.batchNo];
return details;
}

}
function deleteUser(string memory _aadharId)public onlyAdmin {
require((bytes(aadharToUser[_aadharId].aadharId).length > 0), "User not found");
Details memory person = aadharToUser[_aadharId];
person.aadharId = "";
list[aadharToAddress[_aadharId]] = person;
aadharToUser[_aadharId] = person;

added[_aadharId] = false;
count--;
restrictedUser[aadharToAddress[_aadharId]] = true;
}

function restrictUser(string memory _aadharId)public onlyAdmin {
restrictedUser[aadharToAddress[_aadharId]] = true;
}

}
Loading