feat: force-login and open-register config
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-10-07 17:29:26 +08:00
parent b737505f3f
commit 63b7768f78
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
42 changed files with 88 additions and 103 deletions

View File

@ -53,6 +53,8 @@ return [
] ]
], ],
'switch' => [ 'switch' => [
'blog-domain-mode' => 3 'blog-domain-mode' => 3,
'force-login' => true,
'open-register' => false
] ]
]; ];

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,11 +1,11 @@
<?php <?php
requirePHPLib('form'); requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

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

View File

@ -4,7 +4,7 @@
$REQUIRE_LIB['bootstrap5'] = ''; $REQUIRE_LIB['bootstrap5'] = '';
$REQUIRE_LIB['mathjax'] = ''; $REQUIRE_LIB['mathjax'] = '';
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }

View File

@ -1,13 +1,9 @@
<?php <?php
requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check()) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { requirePHPLib('form');
become403Page();
}
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) { if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
become404Page(); become404Page();

View File

@ -1,11 +1,11 @@
<?php <?php
requirePHPLib('form'); requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -5,14 +5,13 @@
become404Page(); become404Page();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
genMoreContestInfo($contest); genMoreContestInfo($contest);
if (!Auth::check()) { if (!Auth::check()) {
redirectToLogin(); redirectToLogin();
} elseif (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
} elseif (hasRegistered($myUser, $contest) || $contest['cur_progress'] != CONTEST_NOT_STARTED) { } elseif (hasRegistered($myUser, $contest) || $contest['cur_progress'] != CONTEST_NOT_STARTED) {
redirectTo('/contests'); redirectTo('/contests');
} }

View File

@ -1,7 +1,7 @@
<?php <?php
requirePHPLib('form'); requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }

View File

@ -1,11 +1,11 @@
<?php <?php
requirePHPLib('judger'); requirePHPLib('judger');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser) && $_GET['type'] != 'attachment') { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login'] && $_GET['type'] != 'attachment') {
become403Page(); become403Page();
} }

View File

@ -3,11 +3,11 @@
requirePHPLib('judger'); requirePHPLib('judger');
requirePHPLib('data'); requirePHPLib('data');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,15 +1,11 @@
<?php <?php
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
if (!Auth::check()) { if (!Auth::check()) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { requirePHPLib('form');
become403Page(); requirePHPLib('judger');
} requirePHPLib('data');
$group_id = $_GET['id']; $group_id = $_GET['id'];
if (!validateUInt($group_id) || !($group = queryGroup($group_id))) { if (!validateUInt($group_id) || !($group = queryGroup($group_id))) {

View File

@ -3,11 +3,11 @@
requirePHPLib('judger'); requirePHPLib('judger');
requirePHPLib('data'); requirePHPLib('data');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,11 +1,11 @@
<?php <?php
requirePHPLib('form'); requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -67,8 +67,8 @@
<?php endif ?> <?php endif ?>
</div> </div>
</div> </div>
<?php if (Auth::check()): ?> <?php if (!UOJConfig::$data['switch']['force-login'] || Auth::check()): ?>
<?php if (isNormalUser($myUser)): ?> <?php if (!UOJConfig::$data['switch']['force-login'] || isNormalUser($myUser)): ?>
<div class="mt-4 <div class="mt-4
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>

View File

@ -2,7 +2,7 @@
requirePHPLib('form'); requirePHPLib('form');
requirePHPLib('judger'); requirePHPLib('judger');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
@ -54,7 +54,7 @@
become404Page(); become404Page();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }
} }

View File

@ -1,15 +1,11 @@
<?php <?php
requirePHPLib('form'); if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
requirePHPLib('judger');
requirePHPLib('data');
if (!Auth::check()) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { requirePHPLib('form');
become403Page(); requirePHPLib('judger');
} requirePHPLib('data');
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();

View File

@ -1,8 +1,12 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
requirePHPLib('form'); requirePHPLib('form');
requirePHPLib('judger'); requirePHPLib('judger');
requirePHPLib('data'); requirePHPLib('data');

View File

@ -1,5 +1,5 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }

View File

@ -1,8 +1,12 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
if (!isset($_COOKIE['bootstrap4'])) { if (!isset($_COOKIE['bootstrap4'])) {
$REQUIRE_LIB['bootstrap5'] = ''; $REQUIRE_LIB['bootstrap5'] = '';
} }

View File

@ -1,14 +1,10 @@
<?php <?php
requirePHPLib('form'); requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -3,11 +3,11 @@
requirePHPLib('judger'); requirePHPLib('judger');
requirePHPLib('data'); requirePHPLib('data');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -4,10 +4,14 @@
$REQUIRE_LIB['bootstrap5'] = ''; $REQUIRE_LIB['bootstrap5'] = '';
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -1,14 +1,10 @@
<?php <?php
requirePHPLib('form'); requirePHPLib('form');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }

View File

@ -1,5 +1,5 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
@ -29,7 +29,7 @@
become404Page(); become404Page();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -13,7 +13,7 @@
return "无效表单"; return "无效表单";
} }
if (DB::selectCount("SELECT COUNT(*) FROM user_info")) { if (!UOJConfig::$data['switch']['open-register'] && DB::selectCount("SELECT COUNT(*) FROM user_info")) {
return "只有首位用户可以注册。"; return "只有首位用户可以注册。";
} }

View File

@ -3,7 +3,7 @@
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -2,7 +2,7 @@
requirePHPLib('form'); requirePHPLib('form');
requirePHPLib('judger'); requirePHPLib('judger');
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
@ -25,7 +25,7 @@
} else { } else {
$contest = null; $contest = null;
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
@ -18,7 +18,7 @@ foreach ($_GET['get'] as $id) {
if ($submission['submitter'] !== Auth::id()) { if ($submission['submitter'] !== Auth::id()) {
become403Page(); become403Page();
} }
if ($submission['contest_id'] == null && !isNormalUser($myUser)) { if ($submission['contest_id'] == null && !(isNormalUser($myUser) && UOJConfig::$data['switch']['force-login'])) {
become403Page(); become403Page();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -5,7 +5,7 @@
requirePHPLib('form'); requirePHPLib('form');
requirePHPLib('judger'); requirePHPLib('judger');
if ($myUser == null || !isSuperUser($myUser)) { if (!isSuperUser($myUser)) {
become403Page(); become403Page();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page(); become403Page();
} }

View File

@ -1,12 +1,8 @@
<?php <?php
if (!Auth::check()) { if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin(); redirectToLogin();
} }
if (!isNormalUser($myUser)) {
become403Page();
}
$header_row = <<<EOD $header_row = <<<EOD
<tr> <tr>
<th>消息</th> <th>消息</th>

View File

@ -167,7 +167,7 @@ mb-4" role="navigation">
<?= UOJLocale::get('login') ?> <?= UOJLocale::get('login') ?>
</a> </a>
</li> </li>
<?php if (!DB::selectCount("SELECT COUNT(*) FROM user_info")): ?> <?php if (UOJConfig::$data['switch']['open-register'] || !DB::selectCount("SELECT COUNT(*) FROM user_info")): ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/register') ?>"> <a class="nav-link" href="<?= HTML::url('/register') ?>">
<i class="bi bi-person-plus-fill"></i> <i class="bi bi-person-plus-fill"></i>

View File

@ -212,7 +212,7 @@ mb-4" role="navigation">
<?= UOJLocale::get('login') ?> <?= UOJLocale::get('login') ?>
</a> </a>
</li> </li>
<?php if (!DB::selectCount("SELECT COUNT(*) FROM user_info")): ?> <?php if (UOJConfig::$data['switch']['open-register'] || !DB::selectCount("SELECT COUNT(*) FROM user_info")): ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/register') ?>"> <a class="nav-link" href="<?= HTML::url('/register') ?>">
<i class="bi bi-person-plus-fill"></i> <i class="bi bi-person-plus-fill"></i>

View File

@ -278,7 +278,7 @@
<li class="nav-item" role="presentation"><a class="nav-link" href="<?= HTML::url('/logout?_token='.crsf_token()) ?>"><?= UOJLocale::get('logout') ?></a></li> <li class="nav-item" role="presentation"><a class="nav-link" href="<?= HTML::url('/logout?_token='.crsf_token()) ?>"><?= UOJLocale::get('logout') ?></a></li>
<?php else: ?> <?php else: ?>
<li class="nav-item" role="presentation"><a class="nav-link" href="<?= HTML::url('/login') ?>"><?= UOJLocale::get('login') ?></a></li> <li class="nav-item" role="presentation"><a class="nav-link" href="<?= HTML::url('/login') ?>"><?= UOJLocale::get('login') ?></a></li>
<?php if (!DB::selectCount("SELECT COUNT(*) FROM user_info")): ?> <?php if (UOJConfig::$data['switch']['open-register'] || !DB::selectCount("SELECT COUNT(*) FROM user_info")): ?>
<li class="nav-item" role="presentation"><a class="nav-link" href="<?= HTML::url('/register') ?>"><?= UOJLocale::get('register') ?></a></li> <li class="nav-item" role="presentation"><a class="nav-link" href="<?= HTML::url('/register') ?>"><?= UOJLocale::get('register') ?></a></li>
<?php endif ?> <?php endif ?>
<?php endif ?> <?php endif ?>

View File

@ -1,5 +1,4 @@
<?php if (Auth::check()): ?> <?php if (Auth::check()): ?>
<?php if (!isset($group_announcements_hidden)): ?> <?php if (!isset($group_announcements_hidden)): ?>
<?php $groups = queryGroupsOfUser(Auth::id()); ?> <?php $groups = queryGroupsOfUser(Auth::id()); ?>
<?php if (count($groups)): ?> <?php if (count($groups)): ?>
@ -30,9 +29,11 @@
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>
</div> </div>
<?php endif ?> <?php endif // count($groups) ?>
<?php endif ?> <?php endif // !isset($group_announcements_hidden) ?>
<?php endif // Auth::check() ?>
<?php if (!UOJConfig::$data['switch']['force-login'] || Auth::check()): ?>
<?php if (!isset($upcoming_contests_hidden)): ?> <?php if (!isset($upcoming_contests_hidden)): ?>
<?php <?php
$upcoming_contests = DB::selectAll("SELECT * FROM contests WHERE status = 'unfinished' ORDER BY start_time ASC, id ASC LIMIT 7"); $upcoming_contests = DB::selectAll("SELECT * FROM contests WHERE status = 'unfinished' ORDER BY start_time ASC, id ASC LIMIT 7");
@ -81,6 +82,5 @@
</a> </a>
</div> </div>
</div> </div>
<?php endif ?> <?php endif // !isset($upcoming_contests_hidden) ?>
<?php endif // !UOJConfig::$data['switch']['force-login'] || Auth::check() ?>
<?php endif // Auth::check() ?>