@@ -4,30 +4,52 @@ pragma solidity >=0.8.20 <0.9.0;
44
55import "./users.sol " ;
66
7+ /**
8+ * @title User Database Control
9+ * @dev A contract for allowing user control over their account.
10+ */
711contract UserControl is UserDatabase {
812
913 address public owner;
1014 uint256 [] _userList;
1115
12- mapping (string platformName = > uint256 ) _platformId;
13- mapping (uint256 platformId = > string ) _platformName;
16+ mapping (string => uint256 ) _platformId;
17+ mapping (uint256 => string ) _platformName;
1418
19+ /**
20+ * @dev Modifier to only allow the owner to execute a function.
21+ */
1522 modifier onlyOwner {
1623 require (msg .sender == owner);
1724 _;
1825 }
1926
20- mapping (address admin = > bool ) _isAdmin;
21-
27+ /**
28+ * @dev Modifier to only allow admins to execute a function.
29+ */
2230 modifier onlyAdmin {
2331 require (msg .sender == owner || _isAdmin[msg .sender ], "onlyAdmin " );
2432 _;
2533 }
2634
35+ /**
36+ * @dev Mapping to store admin status.
37+ */
38+ mapping (address => bool ) _isAdmin;
39+
40+ /**
41+ * @dev Function to toggle admin status.
42+ * @param admin The address of the admin to toggle.
43+ */
2744 function toggleAdmin (address admin ) external onlyOwner {
2845 _isAdmin[admin] = ! _isAdmin[admin];
2946 }
3047
48+ /**
49+ * @dev Constructor to initialize the contract.
50+ * @param platformIds Array of platform IDs.
51+ * @param platformNames Array of platform names.
52+ */
3153 constructor (
3254 uint256 [] memory platformIds ,
3355 string [] memory platformNames
@@ -40,37 +62,76 @@ contract UserControl is UserDatabase {
4062 }
4163 }
4264
65+ /**
66+ * @dev Function to set a platform.
67+ * @param id The ID of the platform.
68+ * @param name The name of the platform.
69+ */
4370 function setPlatform (uint256 id , string memory name ) public onlyAdmin {
4471 _platformId[name] = id;
4572 _platformName[id] = name;
4673 }
4774
75+ /**
76+ * @dev Function to get the ID of a platform.
77+ * @param name The name of the platform.
78+ * @return The ID of the platform.
79+ */
4880 function getPlatformId (string memory name ) public view returns (uint256 ) {
4981 return _platformId[name];
5082 }
5183
84+ /**
85+ * @dev Function to get the name of a platform.
86+ * @param id The ID of the platform.
87+ * @return The name of the platform.
88+ */
5289 function getPlatformName (uint256 id ) public view returns (string memory ) {
5390 return _platformName[id];
5491 }
5592
56-
93+ /**
94+ * @dev Function to override user data.
95+ * @param id The ID of the user.
96+ * @param newData The new user data.
97+ */
5798 function overrideUserData (uint256 id , UserData calldata newData ) external onlyAdmin {
5899 _setUserData (id, newData);
59100 }
60101
102+ /**
103+ * @dev Function to safely override user data.
104+ * @param userAddress The address of the user.
105+ * @param newData The new user data.
106+ */
61107 function safeOverrideUserData (address userAddress , UserData memory newData ) external onlyAdmin {
62108 _safeSetUserData (userAddress, newData);
63109 }
64110
65- ///@notice allows advanced users to set their own data using the full object.
111+ /**
112+ * @dev Function to set user data.
113+ * @param newData The new user data.
114+ */
66115 function setUserData (UserData calldata newData ) public {
67116 _safeSetUserData (msg .sender , newData);
68117 }
69118
119+ /**
120+ * @dev Function to verify a profile.
121+ * @param userAddress The address of the user.
122+ * @param profile The profile to verify.
123+ * @param verified Whether the profile is verified.
124+ */
70125 function verifyProfile (address userAddress , Profile calldata profile , bool verified ) external onlyAdmin {
71126 _verifyProfile (userAddress, profile, verified);
72127 }
73128
129+ /**
130+ * @dev Function to register a new user.
131+ * @param username The username of the user.
132+ * @param bio The bio of the user.
133+ * @param imgUrl The image URL of the user.
134+ */
74135 function register (string memory username , string memory bio , string memory imgUrl ) external {
75136
76137 UserData memory newData = UserData (
@@ -86,10 +147,19 @@ contract UserControl is UserDatabase {
86147 _userList.push (_getId (msg .sender ));
87148 }
88149
150+ /**
151+ * @dev Function to add a user to the user list.
152+ * @param id The ID of the user.
153+ */
89154 function addToUserList (uint256 id ) external onlyAdmin () {
90155 _userList.push (id);
91156 }
92157
158+ /**
159+ * @dev Function to link a profile to a user.
160+ * @param platform The platform of the profile.
161+ * @param id The ID of the profile.
162+ */
93163 function linkProfile (string memory platform , string memory id ) external {
94164 require (isUser (msg .sender ), "Must be a user " );
95165 uint256 platformId = getPlatformId (platform);
@@ -114,6 +184,10 @@ contract UserControl is UserDatabase {
114184
115185 }
116186
187+ /**
188+ * @dev Function to update user data.
189+ * @param newData The updated UserData object.
190+ */
117191 function updateUser (UserData calldata newData ) external {
118192 require (msg .sender == newData.defaultAddress, "Can only update own userData " );
119193 _safeSetUserData (msg .sender , newData);
0 commit comments