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' => [
'blog-domain-mode' => 3
'blog-domain-mode' => 3,
'force-login' => true,
'open-register' => false
]
];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -167,7 +167,7 @@ mb-4" role="navigation">
<?= 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">
<a class="nav-link" href="<?= HTML::url('/register') ?>">
<i class="bi bi-person-plus-fill"></i>

View File

@ -212,7 +212,7 @@ mb-4" role="navigation">
<?= 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">
<a class="nav-link" href="<?= HTML::url('/register') ?>">
<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>
<?php else: ?>
<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>
<?php endif ?>
<?php endif ?>

View File

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