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'));
}
if (!isNormalUser($myUser)) {
become403Page();
}
requirePHPLib('form');
if (!isSuperUser($myUser)) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -129,19 +129,41 @@ function blog_name_decode($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) {
if ($user == null) {
return false;
}
$usertype = explode(',', $user['usertype']);
return in_array('problem_uploader', $usertype);
return hasUserType($user, 'problem_uploader');
}
function isProblemManager($user) {
if ($user == null) {
return false;
}
$usertype = explode(',', $user['usertype']);
return in_array('problem_manager', $usertype);
return hasUserType($user, 'problem_manager');
}
function isSuperUser($user) {
@ -194,20 +216,3 @@ function sendSystemMsg($username, $title, $content) {
$title = DB::escape($title);
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;
}