[ 'name' => ' 个人资料', 'url' => "/user/{$user['username']}/edit/profile", ], 'password' => [ 'name' => ' 修改密码', 'url' => "/user/{$user['username']}/edit/password", ], ]; if (!isset($tabs_info[$cur_tab])) { become404Page(); } if ($cur_tab == 'profile') { $update_profile_form = new UOJForm('update_profile'); $username = UOJLocale::get('username'); $avatar = UOJLocale::get('avatar'); $change_avatar_help = UOJLocale::get('change avatar help'); $update_profile_form->appendHTML(<<
用户名不能被修改。
$avatar
$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', $user['github'], function($github, &$vdata) { if ($github && !validateGitHubUsername($github)) { return 'GitHub 用户名不合法。'; } $vdata['github'] = $github; return ''; }, null); if (isSuperUser($myUser)) { $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(<<
只有管理员才能修改用户所属学校。
EOD); } $update_profile_form->addVSelect('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_handle', 'text', UOJLocale::get('codeforces handle'), $user['codeforces_handle'], function($codeforces_handle, &$vdata) { if ($codeforces_handle && !validateUsername($codeforces_handle)) { return 'Codeforces 用户名格式不合法。'; } $vdata['codeforces_handle'] = $codeforces_handle; return ''; }, null); $update_profile_form->addVInput('website', 'text', UOJLocale::get('user::website'), $user['website'], function($url, &$vdata) { if ($url && !validateURL($url)) { return '链接格式不合法。'; } $vdata['website'] = $url; return ''; }, null); $update_profile_form->handle = function(&$vdata) use ($user, $myUser) { $esc_email = DB::escape($vdata['email']); $esc_qq = DB::escape($vdata['qq']); $esc_github = DB::escape($vdata['github']); $esc_sex = DB::escape($_POST['sex']); $esc_motto = DB::escape($vdata['motto']); $esc_codeforces_handle = DB::escape($vdata['codeforces_handle']); $esc_website = DB::escape($vdata['website']); if (isSuperUser($myUser)) { $esc_school = DB::escape($vdata['school']); DB::update("UPDATE user_info SET school = '$esc_school' WHERE username = '{$user['username']}'"); } DB::update("UPDATE user_info SET email = '$esc_email', qq = '$esc_qq', sex = '$esc_sex', motto = '$esc_motto', codeforces_handle = '$esc_codeforces_handle', github = '$esc_github', website = '$esc_website' WHERE username = '{$user['username']}'"); }; $update_profile_form->submit_button_config['margin_class'] = 'mt-3'; $update_profile_form->submit_button_config['text'] = '更新'; $update_profile_form->runAtServer(); } elseif ($cur_tab == 'password') { if (isset($_POST['submit-change_password']) && $_POST['submit-change_password'] == 'change_password') { header('Content-Type: application/json'); $old_password = $_POST['current_password']; $new_password = $_POST['new_password']; if (!validatePassword($old_password) || !checkPassword($user, $old_password)) { die(json_encode(['status' => 'error', 'message' => '旧密码错误'])); } if (!validatePassword($new_password)) { die(json_encode(['status' => 'error', 'message' => '新密码不合法'])); } if ($old_password == $new_password) { die(json_encode(['status' => 'error', 'message' => '新密码不能与旧密码相同'])); } $password = getPasswordToStore($new_password, $user['username']); DB::update("UPDATE `user_info` SET `password` = '$password' where `username` = '{$user['username']}'"); die(json_encode(['status' => 'success', 'message' => '密码修改成功'])); } } $pageTitle = $user['username'] == $myUser['username'] ? UOJLocale::get('modify my profile') : UOJLocale::get('modify his profile', $user['username']) ?>

$tab): ?>
"> 返回
printHTML() ?>