feat(web): add contest only user type

This commit is contained in:
Baoshuo Ren 2022-04-03 18:18:17 +08:00
parent e1efee927b
commit 27c1eee037
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
30 changed files with 153 additions and 25 deletions

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
requirePHPLib('form'); requirePHPLib('form');
if (!isSuperUser($myUser)) { if (!isSuperUser($myUser)) {

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
requirePHPLib('form'); requirePHPLib('form');
function echoBlogCell($blog) { function echoBlogCell($blog) {

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id']))) { if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
function echoBlogCell($blog) { function echoBlogCell($blog) {
echo '<tr>'; echo '<tr>';
if ($blog['is_hidden']) { if ($blog['is_hidden']) {

View File

@ -2,6 +2,11 @@
if (!Auth::check()) { if (!Auth::check()) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
function handlePost() { function handlePost() {
global $myUser; global $myUser;
if (!isset($_POST['old_password'])) { if (!isset($_POST['old_password'])) {
@ -183,4 +188,3 @@
}); });
</script> </script>
<?php echoUOJPageFooter() ?> <?php echoUOJPageFooter() ?>

View File

@ -18,6 +18,10 @@
if ($myUser == null || !hasRegistered(Auth::user(), $contest)) { if ($myUser == null || !hasRegistered(Auth::user(), $contest)) {
becomeMsgPage("<h1>比赛正在进行中</h1><p>很遗憾,您尚未报名。比赛结束后再来看吧~</p>"); becomeMsgPage("<h1>比赛正在进行中</h1><p>很遗憾,您尚未报名。比赛结束后再来看吧~</p>");
} }
} else {
if (!isNormalUser($myUser)) {
become403Page();
}
} }
} }

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) { if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) { if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -4,6 +4,11 @@
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) { if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
become404Page(); become404Page();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
genMoreContestInfo($contest); genMoreContestInfo($contest);
if (!Auth::check()) { if (!Auth::check()) {

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
switch ($_GET['type']) { switch ($_GET['type']) {
case 'problem': case 'problem':
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {

View File

@ -3,6 +3,14 @@
requirePHPLib('judger'); requirePHPLib('judger');
requirePHPLib('data'); requirePHPLib('data');
if (!Auth::check()) {
become403Page(UOJLocale::get('need login'));
}
if (!isNormalUser($myUser)) {
become403Page();
}
$group_id = $_GET['id']; $group_id = $_GET['id'];
$group = queryGroup($group_id); $group = queryGroup($group_id);

View File

@ -3,6 +3,14 @@
requirePHPLib('judger'); requirePHPLib('judger');
requirePHPLib('data'); requirePHPLib('data');
if (!Auth::check()) {
become403Page(UOJLocale::get('need login'));
}
if (!isNormalUser($myUser)) {
become403Page();
}
if (isSuperUser($myUser)) { if (isSuperUser($myUser)) {
$new_group_form = new UOJForm('new_group'); $new_group_form = new UOJForm('new_group');
$new_group_form->handle = function() { $new_group_form->handle = function() {

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($hack = queryHack($_GET['id']))) { if (!validateUInt($_GET['id']) || !($hack = queryHack($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
$conds = array(); $conds = array();
$q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null; $q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null;

View File

@ -44,7 +44,7 @@
</div> </div>
</div> </div>
<?php if (Auth::check()): ?> <?php if (Auth::check() && isNormalUser($myUser)): ?>
<div class="row"> <div class="row">
<div class="col-sm-12 mt-4"> <div class="col-sm-12 mt-4">
<h3><?= UOJLocale::get('top solver') ?></h3> <h3><?= UOJLocale::get('top solver') ?></h3>

View File

@ -44,6 +44,10 @@
if (!isProblemVisibleToUser($problem, $myUser)) { if (!isProblemVisibleToUser($problem, $myUser)) {
become404Page(); become404Page();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
} }
$submission_requirement = json_decode($problem['submission_requirement'], true); $submission_requirement = json_decode($problem['submission_requirement'], true);

View File

@ -7,6 +7,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -7,6 +7,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) { if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) {
$new_problem_form = new UOJForm('new_problem'); $new_problem_form = new UOJForm('new_problem');
$new_problem_form->handle = function() { $new_problem_form->handle = function() {

View File

@ -5,6 +5,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -17,6 +17,10 @@
if (!isProblemVisibleToUser($problem, $myUser)) { if (!isProblemVisibleToUser($problem, $myUser)) {
become404Page(); become404Page();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
} }
function scoreDistributionData() { function scoreDistributionData() {

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (isset($_GET['type']) && $_GET['type'] == 'accepted') { if (isset($_GET['type']) && $_GET['type'] == 'accepted') {
$config = array('page_len' => 100, 'by_accepted' => true); $config = array('page_len' => 100, 'by_accepted' => true);
$title = UOJLocale::get('top solver'); $title = UOJLocale::get('top solver');

View File

@ -19,6 +19,10 @@
genMoreContestInfo($contest); genMoreContestInfo($contest);
} else { } else {
$contest = null; $contest = null;
if (!isNormalUser($myUser)) {
become403Page();
}
} }
if (!isSubmissionVisibleToUser($submission, $problem, $myUser)) { if (!isSubmissionVisibleToUser($submission, $problem, $myUser)) {
become403Page(); become403Page();

View File

@ -18,6 +18,9 @@ foreach ($_GET['get'] as $id) {
if ($submission['submitter'] !== Auth::id()) { if ($submission['submitter'] !== Auth::id()) {
become403Page(); become403Page();
} }
if ($submission['contest_id'] == null && !isNormalUser($myUser)) {
become403Page();
}
$problem = queryProblemBrief($submission['problem_id']); $problem = queryProblemBrief($submission['problem_id']);
if (!isSubmissionVisibleToUser($submission, $problem, Auth::user())) { if (!isSubmissionVisibleToUser($submission, $problem, Auth::user())) {

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
$conds = array(); $conds = array();
$q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null; $q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null;

View File

@ -124,6 +124,7 @@
'normaluser' => '设为普通用户', 'normaluser' => '设为普通用户',
'problem_uploader' => '设为题目上传者', 'problem_uploader' => '设为题目上传者',
'problem_manager' => '设为题目管理员', 'problem_manager' => '设为题目管理员',
'contest_only' => '设为仅比赛参加者',
'superuser' => '设为超级用户' 'superuser' => '设为超级用户'
); );
$user_form->addSelect('op_type', $options, '操作类型', ''); $user_form->addSelect('op_type', $options, '操作类型', '');
@ -152,6 +153,12 @@
$user = addUserType($user, 'problem_manager'); $user = addUserType($user, 'problem_manager');
DB::update("update user_info set usertype = '{$user['usertype']}' where username = '{$username}'"); DB::update("update user_info set usertype = '{$user['usertype']}' where username = '{$username}'");
break; break;
case 'contest_only':
DB::update("update user_info set usergroup = 'U' where username = '{$username}'");
$user = queryUser($username);
$user = addUserType($user, 'contest_only');
DB::update("update user_info set usertype = '{$user['usertype']}' where username = '{$username}'");
break;
case 'superuser': case 'superuser':
DB::update("update user_info set usergroup = 'S' where username = '{$username}'"); DB::update("update user_info set usergroup = 'S' where username = '{$username}'");
break; break;

View File

@ -3,6 +3,10 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) {
become403Page();
}
$username = $_GET['username']; $username = $_GET['username'];
$REQUIRE_LIB['github_contribution_graph'] = ''; $REQUIRE_LIB['github_contribution_graph'] = '';

View File

@ -3,6 +3,10 @@
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
function handleMsgPost() { function handleMsgPost() {
global $myUser; global $myUser;
if (!isset($_POST['receiver'])) { if (!isset($_POST['receiver'])) {

View File

@ -3,6 +3,10 @@
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
$header_row = <<<EOD $header_row = <<<EOD
<tr> <tr>
<th>消息</th> <th>消息</th>

View File

@ -129,19 +129,41 @@ function blog_name_decode($name) {
return $name; return $name;
} }
function addUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
if (!in_array($type, $usertype)) {
$usertype[] = $type;
}
$user['usertype'] = implode(',', $usertype);
return $user;
}
function removeUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
if (in_array($type, $usertype)) {
$usertype = array_diff($usertype, array($type));
}
$user['usertype'] = implode(',', $usertype);
return $user;
}
function hasUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
return in_array($type, $usertype);
}
function isNormalUser($user) {
return $user != null && !hasUserType($user, 'contest_only');
}
function isProblemUploader($user) { function isProblemUploader($user) {
if ($user == null) { if ($user == null) {
return false; return false;
} }
$usertype = explode(',', $user['usertype']); return hasUserType($user, 'problem_uploader');
return in_array('problem_uploader', $usertype);
} }
function isProblemManager($user) { function isProblemManager($user) {
if ($user == null) { if ($user == null) {
return false; return false;
} }
$usertype = explode(',', $user['usertype']); return hasUserType($user, 'problem_manager');
return in_array('problem_manager', $usertype);
} }
function isSuperUser($user) { function isSuperUser($user) {
@ -194,20 +216,3 @@ function sendSystemMsg($username, $title, $content) {
$title = DB::escape($title); $title = DB::escape($title);
DB::insert("insert into user_system_msg (receiver, title, content, send_time) values ('$username', '$title', '$content', now())"); DB::insert("insert into user_system_msg (receiver, title, content, send_time) values ('$username', '$title', '$content', now())");
} }
function addUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
if (!in_array($type, $usertype)) {
$usertype[] = $type;
}
$user['usertype'] = implode(',', $usertype);
return $user;
}
function removeUserType($user, $type) {
$usertype = explode(',', $user['usertype']);
if (in_array($type, $usertype)) {
$usertype = array_diff($usertype, array($type));
}
$user['usertype'] = implode(',', $usertype);
return $user;
}