feat(web): multiple permissions for user

This commit is contained in:
Baoshuo Ren 2022-04-02 17:09:49 +08:00
parent a5a3fb9288
commit 0af24b52ac
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 25 additions and 5 deletions

View File

@ -142,11 +142,23 @@
break;
case 'problem_uploader':
DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
DB::update("update user_info set usertype = 'problem_uploader' where username = '{$username}'");
$user = queryUser($username);
$usertype = explode(',', $user['usertype']);
if (!in_array('problem_uploader', $usertype)) {
$usertype[] = 'problem_uploader';
}
$usertype = implode(',', $usertype);
DB::update("update user_info set usertype = '{$usertype}' where username = '{$username}'");
break;
case 'problem_manager':
DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
DB::update("update user_info set usertype = 'problem_manager' where username = '{$username}'");
$user = queryUser($username);
$usertype = explode(',', $user['usertype']);
if (!in_array('problem_manager', $usertype)) {
$usertype[] = 'problem_manager';
}
$usertype = implode(',', $usertype);
DB::update("update user_info set usertype = '{$usertype}' where username = '{$username}'");
break;
case 'superuser':
DB::update("update user_info set usergroup = 'S' where username = '{$username}'");
@ -427,7 +439,7 @@ EOD;
echo <<<EOD
<tr>
<td>${hislink}</td>
<td>{$row['usergroup']}</td>
<td>{$row['usergroup']}, {$row['usertype']}</td>
<td>{$row['register_time']}</td>
</tr>
EOD;

View File

@ -130,10 +130,18 @@ function blog_name_decode($name) {
}
function isProblemUploader($user) {
return $user != null && $user['usertype'] == 'problem_uploader';
if ($user == null) {
return false;
}
$usertype = explode(',', $user['usertype']);
return in_array('problem_uploader', $usertype);
}
function isProblemManager($user) {
return $user != null && $user['usertype'] == 'problem_manager';
if ($user == null) {
return false;
}
$usertype = explode(',', $user['usertype']);
return in_array('problem_manager', $usertype);
}
function isSuperUser($user) {