Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
179 lines
9.3 KiB
PHP
179 lines
9.3 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: AKSRT - Reset Password
|
|
* Template Post Type: page
|
|
*
|
|
* Theme auth route template: /reset-password/
|
|
*
|
|
* 统一处理:
|
|
* 1. 忘记密码(无 token 参数)— 输入邮箱/用户名请求重置
|
|
* 2. 设置密码(有 token+uid 参数)— 邮件链接进入后设置新密码
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
// ============================================
|
|
// 检测当前模式:设置密码 or 请求重置
|
|
// ============================================
|
|
$context = \AKSRT\Auth\Service::get_reset_context($_GET);
|
|
$mode = $context['mode'];
|
|
$errors = [];
|
|
$success = '';
|
|
$token = $context['token'];
|
|
$user_id = $context['user_id'];
|
|
|
|
if (!empty($context['error'])) {
|
|
$errors[] = $context['error'];
|
|
}
|
|
|
|
// ============================================
|
|
// 处理表单提交
|
|
// ============================================
|
|
|
|
// 模式1:请求重置密码(忘记密码表单提交)
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['aksrt_action']) && $_POST['aksrt_action'] === 'request_reset') {
|
|
$result = \AKSRT\Auth\Service::request_password_reset($_POST);
|
|
if (!empty($result['success'])) {
|
|
$success = $result['message'] ?? __('如果该账号存在,重置邮件已发送到注册邮箱', 'aksrt');
|
|
} else {
|
|
$errors[] = $result['error'] ?? __('重置请求失败,请稍后重试', 'aksrt');
|
|
}
|
|
}
|
|
|
|
// 模式2:设置新密码(从邮件链接进入)
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['aksrt_action']) && $_POST['aksrt_action'] === 'set_password') {
|
|
$result = \AKSRT\Auth\Service::reset_password_with_token($_POST);
|
|
if (!empty($result['success'])) {
|
|
$mode = 'success';
|
|
$success = $result['message'] ?? __('密码已设置成功!', 'aksrt');
|
|
} else {
|
|
$errors[] = $result['error'] ?? __('重置密码失败,请稍后重试', 'aksrt');
|
|
$mode = $result['mode'] ?? 'invalid';
|
|
}
|
|
}
|
|
|
|
remove_action('wp_footer', 'aksrt_render_footer_tabbar', 20);
|
|
remove_action('wp_footer', 'aksrt_render_float_buttons', 30);
|
|
add_filter('body_class', static function ($classes) {
|
|
$classes[] = 'page-template-user-sign';
|
|
return $classes;
|
|
});
|
|
get_header();
|
|
?>
|
|
|
|
<main id="main-content" class="site-main" tabindex="-1">
|
|
<div class="auth-shell">
|
|
<div class="auth-card">
|
|
<div class="auth-card__logo sign-logo" aria-hidden="true"><?php if (function_exists('aksrt_get_auth_sign_logo_html')) { echo aksrt_get_auth_sign_logo_html(); } else { echo 'AK'; } // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
|
<h1 class="auth-card__title"><?php bloginfo('name'); ?></h1>
|
|
|
|
<?php if ($mode === 'success') : ?>
|
|
<!-- 密码设置成功 -->
|
|
<p class="auth-card__subtitle"><?php esc_html_e('密码设置成功!', 'aksrt'); ?></p>
|
|
<div class="alert alert--success" role="alert">
|
|
<span><?php echo esc_html($success); ?></span>
|
|
</div>
|
|
<a href="<?php echo esc_url(aksrt_get_login_url()); ?>" class="btn-primary btn-lg" style="width:100%;display:block;text-align:center;text-decoration:none;margin-top:16px;">
|
|
<?php esc_html_e('立即登录', 'aksrt'); ?>
|
|
</a>
|
|
|
|
<?php elseif ($mode === 'invalid') : ?>
|
|
<!-- 链接无效或已过期 -->
|
|
<p class="auth-card__subtitle"><?php esc_html_e('重置链接无效或已过期', 'aksrt'); ?></p>
|
|
<?php if (!empty($errors)) : ?>
|
|
<div class="alert alert--error" role="alert">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/></svg>
|
|
<span><?php echo esc_html($errors[0]); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
<a href="<?php echo esc_url(aksrt_get_reset_password_url()); ?>" class="btn-primary btn-lg" style="width:100%;display:block;text-align:center;text-decoration:none;margin-top:16px;">
|
|
<?php esc_html_e('重新申请重置密码', 'aksrt'); ?>
|
|
</a>
|
|
|
|
<?php elseif ($mode === 'reset') : ?>
|
|
<!-- 设置新密码表单 -->
|
|
<p class="auth-card__subtitle"><?php esc_html_e('请设置你的新密码', 'aksrt'); ?></p>
|
|
|
|
<?php if (!empty($errors)) : ?>
|
|
<div class="alert alert--error" role="alert">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/></svg>
|
|
<span><?php echo esc_html($errors[0]); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form class="auth-form" id="aksrt-set-password-form" method="post" action="">
|
|
<?php wp_nonce_field('aksrt_set_password', '_setpw_nonce'); ?>
|
|
<input type="hidden" name="aksrt_action" value="set_password">
|
|
<input type="hidden" name="reset_token" value="<?php echo esc_attr($token); ?>">
|
|
<input type="hidden" name="reset_uid" value="<?php echo esc_attr((string) $user_id); ?>">
|
|
|
|
<div class="form-field form-field--pwd">
|
|
<label for="pass1"><?php esc_html_e('新密码', 'aksrt'); ?></label>
|
|
<div class="input-wrap">
|
|
<span class="input-icon" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:18px;height:18px;"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg></span>
|
|
<input type="password" name="pass1" id="pass1" autocomplete="new-password" required minlength="6">
|
|
<button type="button" class="toggle-pwd" data-target="pass1" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:16px;height:16px;"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg></button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-field form-field--pwd">
|
|
<label for="pass2"><?php esc_html_e('确认新密码', 'aksrt'); ?></label>
|
|
<div class="input-wrap">
|
|
<span class="input-icon" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:18px;height:18px;"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg></span>
|
|
<input type="password" name="pass2" id="pass2" autocomplete="new-password" required minlength="6">
|
|
<button type="button" class="toggle-pwd" data-target="pass2" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:16px;height:16px;"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg></button>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-primary btn-lg btn-block"><?php esc_html_e('设置新密码', 'aksrt'); ?></button>
|
|
</form>
|
|
|
|
<?php else : ?>
|
|
<!-- 请求重置密码表单(忘记密码) -->
|
|
<p class="auth-card__subtitle"><?php esc_html_e('输入邮箱或用户名,我们将发送重置链接', 'aksrt'); ?></p>
|
|
|
|
<?php if (!empty($errors)) : ?>
|
|
<div class="alert alert--error" role="alert">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/></svg>
|
|
<span><?php echo esc_html($errors[0]); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($success)) : ?>
|
|
<div class="alert alert--success" role="alert">
|
|
<span><?php echo esc_html($success); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form class="auth-form" id="aksrt-request-reset-form" method="post" action="">
|
|
<?php wp_nonce_field('aksrt_reset_password', '_reset_nonce'); ?>
|
|
<input type="hidden" name="aksrt_action" value="request_reset">
|
|
|
|
<div class="form-field">
|
|
<label for="user_login"><?php esc_html_e('邮箱 / 用户名', 'aksrt'); ?></label>
|
|
<div class="input-wrap">
|
|
<span class="input-icon" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:18px;height:18px;"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg></span>
|
|
<input type="text" name="user_login" id="user_login" autocomplete="username" required>
|
|
</div>
|
|
</div>
|
|
|
|
<?php aksrt_render_captcha('lostpassword'); ?>
|
|
|
|
<button type="submit" class="btn-primary btn-lg btn-block"><?php esc_html_e('发送重置链接', 'aksrt'); ?></button>
|
|
</form>
|
|
|
|
<p class="auth-footer-link">
|
|
<?php esc_html_e('想起密码了?', 'aksrt'); ?>
|
|
<a href="<?php echo esc_url(aksrt_get_login_url()); ?>"><?php esc_html_e('返回登录', 'aksrt'); ?></a>
|
|
</p>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php
|
|
get_footer();
|