From 452c2ca12b35b963a46fe14d5d24be40c742a530 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 14 Jan 2023 17:20:10 +0800 Subject: [PATCH] feat(web/user): username color Co-authored-by: Wenkuo Yu <82705676+youwike@users.noreply.github.com> Co-authored-by: Baoshuo Ren <47095648+renbaoshuo@users.noreply.github.com> --- web/app/controllers/super_manage.php | 2 +- web/app/controllers/user_info_edit.php | 34 +++++++++++++++++++++++++- web/app/models/UOJUser.php | 34 ++++++++++++++++++++++---- web/css/uoj-bs5.css | 7 +++++- web/js/uoj.js | 9 +++++-- 5 files changed, 76 insertions(+), 10 deletions(-) diff --git a/web/app/controllers/super_manage.php b/web/app/controllers/super_manage.php index 113fb1c..ad04c3e 100644 --- a/web/app/controllers/super_manage.php +++ b/web/app/controllers/super_manage.php @@ -1336,7 +1336,7 @@ EOD); EOD, function ($row) { echo ''; - echo '', '', $row['username'], '', ''; + echo '', UOJUser::getLink($row), ''; echo '', HTML::escape($row['school']), ''; echo ''; switch ($row['usergroup']) { diff --git a/web/app/controllers/user_info_edit.php b/web/app/controllers/user_info_edit.php index 7d7dc3a..2a9dfaf 100644 --- a/web/app/controllers/user_info_edit.php +++ b/web/app/controllers/user_info_edit.php @@ -233,6 +233,36 @@ EOD); }, null ); + if ($user['usergroup'] == 'B') { + $update_profile_form->appendHTML(<< + + +
被封禁的用户无法修改用户名颜色。
+ + EOD); + } else if ($user['usergroup'] == 'T') { + $update_profile_form->appendHTML(<< + + +
临时用户无法修改用户名颜色。
+ + EOD); + } else { + $additional_colors = []; + + if (isSuperUser($user)) { + $additional_colors['#9d3dcf'] = '紫色 - #9d3dcf'; + $additional_colors['#fe4c61'] = '红色 - #fe4c61'; + } + + $update_profile_form->addVSelect('username_color', $additional_colors + [ + '#0d6efd' => '蓝色 - #0d6efd', + '#2da44e' => '绿色 - #2da44e', + '#f48fb1' => '粉色 - #f48fb1', + ], '用户名颜色', '#0d6efd'); + } $update_profile_form->handle = function (&$vdata) use ($user) { $data = [ 'email' => $vdata['email'], @@ -268,7 +298,9 @@ EOD); '$.social.codeforces', $vdata['codeforces'], '$.social.website', - $vdata['website'] + $vdata['website'], + '$.username_color', + $_POST['username_color'] ), ], "where", ["username" => $user['username']] diff --git a/web/app/models/UOJUser.php b/web/app/models/UOJUser.php index 46e955e..508305d 100644 --- a/web/app/models/UOJUser.php +++ b/web/app/models/UOJUser.php @@ -221,14 +221,37 @@ class UOJUser { } } - if ($user['usergroup'] == 'B') { - return HTML::tag('a', ['class' => 'text-danger fw-bold', 'href' => "/user/{$user['username']}"], $user['username']); + $extra = UOJUser::getExtra($user); + $realname = $user['realname']; + $color = '#0d6efd'; + + if ($user['usergroup'] === 'B') { + $color = '#996600'; + } else if (isTmpUser($user)) { + $color = '#707070'; + } else { + if (isSuperUser($user)) { + $color = '#9d3dcf'; + } + + $color = $extra['username_color']; + + // 前管理员设置颜色为紫色、红色的,颜色改为蓝色 + if (($color === '#9d3dcf' || $color === '#fe4c61') && !isSuperUser($user)) { + $color = '#0d6efd'; + } } - // 未登录不可查看真实姓名 - $realname = Auth::check() ? $user['realname'] : ''; + if ($user['usertype'] == 'teacher') { + $realname .= '老师'; + } - return HTML::tag('span', ['class' => 'uoj-username', 'data-realname' => trim(HTML::escape($realname))], $user['username']); + return HTML::tag('span', [ + 'class' => 'uoj-username', + // 未登录不可查看真实姓名 + 'data-realname' => Auth::check() ? trim(HTML::escape($realname)) : '', + 'data-color' => $color, + ], $user['username']); } public static function getUpdatedExtraVisitHistory($history, $cur) { @@ -290,6 +313,7 @@ class UOJUser { 'show_email' => 'all', 'show_qq' => 'all', 'avatar_source' => 'gravatar', + 'username_color' => isSuperUser($user) ? '#9d3dcf' : '#0d6efd', ]); return $extra; } diff --git a/web/css/uoj-bs5.css b/web/css/uoj-bs5.css index 6d35ca9..1019f61 100644 --- a/web/css/uoj-bs5.css +++ b/web/css/uoj-bs5.css @@ -25,6 +25,11 @@ a { 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; } +.uoj-realname { + font-size: 90%; + font-weight: normal; +} + h1, .h1 { /* font-size: 2.5rem; */ @@ -164,7 +169,7 @@ h6, .card-uoj-tle > .card-header:hover, .card-uoj-tle > div.card-header > div > .uoj-status-text { - color: sandybrown; + color: #f4a460; } .card-uoj-wrong > .card-header:hover, diff --git a/web/js/uoj.js b/web/js/uoj.js index 61df0fd..267f608 100644 --- a/web/js/uoj.js +++ b/web/js/uoj.js @@ -148,11 +148,16 @@ function getUserSpan(username, realname) { function replaceWithHighlightUsername() { var username = $(this).text(); var realname = $(this).data("realname"); + var color = $(this).data("color"); + var new_elem_inner = ''; + if ($(this).data("link") != 0) { - $(this).replaceWith(getUserLink(username, realname)); + new_elem_inner = getUserLink(username, realname); } else { - $(this).replaceWith(getUserSpan(username, realname)); + new_elem_inner = getUserSpan(username, realname); } + + $(this).replaceWith($(new_elem_inner).css('color', color)); } $.fn.uoj_honor = function() {