[ 'name' => ' 个人资料', 'url' => "/user/{$user['username']}/edit/profile", ], 'password' => [ 'name' => ' 修改密码', 'url' => "/user/{$user['username']}/edit/password", ], 'privilege' => [ 'name' => ' 特权', 'url' => "/user/{$user['username']}/edit/privilege", ] ]; if (!isset($tabs_info[$cur_tab])) { become404Page(); } if ($cur_tab == 'profile') { $update_profile_form = new UOJBs4Form('update_profile'); $username = UOJLocale::get('username'); $avatar = UOJLocale::get('avatar'); $update_profile_form->appendHTML(<< $username 用户名不能被修改。 EOD); if (isSuperUser(Auth::user())) { $update_profile_form->addVInput( 'realname', 'text', UOJLocale::get('user::real name'), $user['realname'], function ($realname, &$vdata) { $vdata['realname'] = $realname; return ''; }, null ); } else { $real_name = UOJLocale::get('user::real name'); $update_profile_form->appendHTML(<< $real_name 只有管理员才能修改用户的真实姓名。 EOD); } $update_profile_form->addVCheckboxes('avatar_source', [ 'gravatar' => 'Gravatar', 'qq' => 'QQ', ], UOJLocale::get('user::avatar source'), $extra['avatar_source'] ?: 'gravatar'); $change_avatar_help = UOJLocale::get('change avatar help'); $update_profile_form->appendHTML(<< $change_avatar_help EOD); $update_profile_form->addVInput( 'email', 'email', UOJLocale::get('email'), $user['email'] ?: '', function ($email, &$vdata) { if (!validateEmail($email)) { return 'Email 格式不合法。'; } $vdata['email'] = $email; return ''; }, null ); $update_profile_form->addVInput( 'qq', 'text', UOJLocale::get('QQ'), $user['qq'] == 0 ? '' : $user['qq'], function ($qq, &$vdata) { if ($qq && !validateQQ($qq)) { return 'QQ 格式不合法。'; } $vdata['qq'] = $qq; return ''; }, null ); $update_profile_form->addVInput( 'github', 'text', 'GitHub', $extra['social']['github'] ?: '', function ($github, &$vdata) { if ($github && !validateGitHubUsername($github)) { return 'GitHub 用户名不合法。'; } $vdata['github'] = $github; return ''; }, null ); if (isSuperUser(Auth::user())) { $update_profile_form->addVInput( 'school', 'text', UOJLocale::get('school'), $user['school'] ?: '', function ($school, &$vdata) { $vdata['school'] = $school; return ''; }, null ); } else { $school = UOJLocale::get('school'); $update_profile_form->appendHTML(<< $school 只有管理员才能修改用户所属学校。 EOD); } $update_profile_form->addVCheckboxes('sex', [ 'U' => UOJLocale::get('refuse to answer'), 'M' => UOJLocale::get('male'), 'F' => UOJLocale::get('female'), ], UOJLocale::get('sex'), $user['sex']); $update_profile_form->addVInput( 'motto', 'text', UOJLocale::get('motto'), $user['motto'] ?: '', function ($motto, &$vdata) { if (!validateMotto($motto)) { return '格言格式不合法'; } $vdata['motto'] = $motto; return ''; }, null ); $update_profile_form->addVInput( 'codeforces', 'text', UOJLocale::get('codeforces handle'), $extra['social']['codeforces'] ?: '', function ($codeforces, &$vdata) { if ($codeforces && !validateUsername($codeforces)) { return 'Codeforces 用户名格式不合法。'; } $vdata['codeforces'] = $codeforces; return ''; }, null ); $update_profile_form->addVInput( 'website', 'text', UOJLocale::get('user::website'), $extra['social']['website'] ?: '', function ($url, &$vdata) { if ($url && !validateURL($url)) { return '链接格式不合法。'; } $vdata['website'] = $url; return ''; }, null ); $update_profile_form->handle = function (&$vdata) use ($user) { $data = [ 'email' => $vdata['email'], 'qq' => $vdata['qq'], 'sex' => $_POST['sex'], 'motto' => $vdata['motto'], ]; if (isSuperUser(Auth::user())) { $data['realname'] = $vdata['realname']; $data['school'] = $vdata['school']; } DB::update([ "update user_info", "set", $data, "where", ["username" => $user['username']] ]); DB::update([ "update user_info", "set", [ 'extra' => DB::json_set( 'extra', '$.avatar_source', $_POST['avatar_source'], '$.social.github', $vdata['github'], '$.social.codeforces', $vdata['codeforces'], '$.social.website', $vdata['website'] ), ], "where", ["username" => $user['username']] ]); dieWithJsonData(['status' => 'success']); }; $update_profile_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3'; $update_profile_form->submit_button_config['text'] = '更新'; $update_profile_form->setAjaxSubmit(<<runAtServer(); } elseif ($cur_tab == 'password') { if (isset($_POST['submit-change_password']) && $_POST['submit-change_password'] == 'change_password') { $old_password = $_POST['current_password']; $new_password = $_POST['new_password']; if (!validatePassword($old_password) || !checkPassword($user, $old_password)) { dieWithJsonData(['status' => 'error', 'message' => '旧密码错误']); } if (!validatePassword($new_password)) { dieWithJsonData(['status' => 'error', 'message' => '新密码不合法']); } if ($old_password == $new_password) { dieWithJsonData(['status' => 'error', 'message' => '新密码不能与旧密码相同']); } DB::update([ "update user_info", "set", [ 'password' => getPasswordToStore($new_password, $user['username']), ], "where", ["username" => $user['username']] ]); dieWithJsonData(['status' => 'success', 'message' => '密码修改成功']); } } elseif ($cur_tab == 'privilege') { if (isset($_POST['submit-privilege']) && $_POST['submit-privilege'] == 'privilege' && isSuperUser(Auth::user())) { $user['usertype'] = 'student'; if ($_POST['user_type'] == 'teacher') { addUserType($user, 'teacher'); removeUserType($user, 'student'); } else { addUserType($user, 'student'); } if ($_POST['problem_uploader'] == 'yes') { addUserType($user, 'problem_uploader'); } if ($_POST['problem_manager'] == 'yes') { addUserType($user, 'problem_manager'); } if ($_POST['contest_judger'] == 'yes') { addUserType($user, 'contest_judger'); } DB::update("UPDATE `user_info` SET `usertype` = '{$user['usertype']}' where `username` = '{$user['username']}'"); dieWithJsonData(['status' => 'success', 'message' => '权限修改成功']); } } $pageTitle = $user['username'] == Auth::id() ? UOJLocale::get('modify my profile') : UOJLocale::get('modify his profile', $user['username']) ?> = $pageTitle ?> = HTML::navListGroup($tabs_info, $cur_tab) ?> "> 返回 您正在使用管理特权查看并编辑其它用户的资料。 printHTML() ?> = UOJLocale::get('current password') ?> = UOJLocale::get('new password') ?> = UOJLocale::get('confirm new password') ?> 如需重置其他用户的密码,请前往 系统管理 页面操作。 更新 = UOJLocale::get('user::user group') ?> = UOJLocale::get('user::super user') ?> = UOJLocale::get('user::banned user') ?> = UOJLocale::get('user::normal user') ?> = UOJLocale::get('user::user type') ?> > = UOJLocale::get('user::student') ?> > = UOJLocale::get('user::teacher') ?> > = UOJLocale::get('user::problem uploader') ?> > = UOJLocale::get('user::problem manager') ?> > = UOJLocale::get('user::contest judger') ?> 更新