addInput('username', [ 'div_class' => '', 'label' => '用户名', 'validator_php' => function ($username, &$vdata) { if (!validateUsername($username)) { return '用户名不合法'; } $vdata['user'] = UOJUser::query($username); if (!$vdata['user']) { return '该用户不存在'; } return ''; }, ]); $enter_verification_code_text = UOJLocale::get('enter verification code'); $forgot_form->appendHTML(<<
EOD); $forgot_form->handle = function (&$vdata) { $user = $vdata['user']; $password = $user["password"]; if (!isset($_SESSION['phrase']) || !PhraseBuilder::comparePhrases($_SESSION['phrase'], $_POST['captcha'])) { unset($_SESSION['phrase']); becomeMsgPage('验证码错误!'); } unset($_SESSION['phrase']); if (!$user['email']) { becomeMsgPage('用户未填写邮件地址,请联系管理员重置!'); } $oj_name = UOJConfig::$data['profile']['oj-name']; $oj_name_short = UOJConfig::$data['profile']['oj-name-short']; $check_code = md5($user['username'] . "+" . $password . '+' . UOJTime::$time_now_str); $sufs = base64url_encode($user['username'] . "." . $check_code); $url = HTML::url("/reset_password", ['params' => ['p' => $sufs]]); $oj_url = HTML::url('/'); $name = $user['username']; $remote_addr = UOJContext::remoteAddr(); $http_x_forwarded_for = UOJContext::httpXForwardedFor(); $user_agent = UOJContext::httpUserAgent(); if ($user['realname']) { $name .= ' (' . $user['realname'] . ')'; } $html = <<

{$name} 您好,

您最近告知我们需要重置您在 {$oj_name_short} 上账号的密码。请访问以下链接:{$url} (如果无法点击链接,请试着复制链接并粘贴至浏览器中打开。)

如果您没有请求重置密码,则忽略此信息。该链接将在 72 小时后自动过期失效。

{$oj_name}

{$oj_url}

EOD; $mailer = UOJMail::noreply(); $mailer->addAddress($user['email'], $user['username']); $mailer->Subject = $oj_name_short . " 密码找回"; $mailer->msgHTML($html); $res = retry_loop(function () use (&$mailer) { $res = $mailer->send(); if ($res) return true; UOJLog::error($mailer->ErrorInfo); return false; }); if (!$res) { becomeMsgPage('

邮件发送失败,请重试!

返回
'); } else { DB::update([ "update user_info", "set", [ 'extra' => DB::json_set('extra', '$.reset_password_check_code', $check_code, '$.reset_password_time', UOJTime::$time_now_str), ], "where", [ "username" => $user['username'], ], ]); becomeMsgPage('

邮件发送成功,请检查收件箱!

如果邮件未出现在收件箱中,请检查垃圾箱。
'); } }; $forgot_form->runAtServer(); ?>

找回密码

printHTML() ?>