150 lines
7.4 KiB
PHP
150 lines
7.4 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: AKSRT - Verify Email
|
|
* Template Post Type: page
|
|
*
|
|
* Theme auth route template: /verify-email/
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
$verify_error = '';
|
|
$verify_success = '';
|
|
$redirect_url = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['verify_email_resend'])) {
|
|
$result = AKSRT_Auth_Service::resend_email_verification($_POST);
|
|
if (!empty($result['success'])) {
|
|
$verify_success = $result['message'] ?? __('验证邮件已重新发送,请注意查收。', 'aksrt');
|
|
} else {
|
|
$verify_error = $result['error'] ?? __('验证邮件发送失败,请稍后重试。', 'aksrt');
|
|
}
|
|
} elseif (isset($_POST['verify_email_submit'])) {
|
|
$result = AKSRT_Auth_Service::verify_email_code_submission($_POST);
|
|
if (!empty($result['success'])) {
|
|
$verify_success = $result['message'] ?? __('邮箱验证成功,即将进入你的账号。', 'aksrt');
|
|
$redirect_url = $result['redirect'] ?? '';
|
|
} else {
|
|
$verify_error = $result['error'] ?? __('邮箱验证码错误或已过期。', 'aksrt');
|
|
}
|
|
}
|
|
}
|
|
|
|
$verify_context = AKSRT_Auth_Service::get_email_verification_context($_GET);
|
|
if ($verify_error === '' && !empty($verify_context['error'])) {
|
|
$verify_error = $verify_context['error'];
|
|
}
|
|
if ($verify_success === '' && !empty($verify_context['message'])) {
|
|
$verify_success = $verify_context['message'];
|
|
}
|
|
if ($redirect_url === '' && !empty($verify_context['redirect'])) {
|
|
$redirect_url = $verify_context['redirect'];
|
|
}
|
|
|
|
$verify_user = $verify_context['user'] ?? null;
|
|
$verify_uid = (int) ($verify_context['uid'] ?? 0);
|
|
$verify_email = (string) ($verify_context['email'] ?? '');
|
|
$verify_mode = (string) ($verify_context['mode'] ?? 'invalid');
|
|
$verify_method= (string) ($verify_context['method'] ?? '');
|
|
$verify_vk = (string) ($verify_context['access_key'] ?? '');
|
|
|
|
get_header();
|
|
?>
|
|
|
|
<main id="main-content" class="site-main" tabindex="-1">
|
|
<div class="auth-shell">
|
|
<div class="auth-card">
|
|
<div class="auth-card__logo" aria-hidden="true">AK</div>
|
|
<h1 class="auth-card__title"><?php bloginfo('name'); ?></h1>
|
|
|
|
<?php if ($verify_mode === 'completed' || $verify_mode === 'verified') : ?>
|
|
<p class="auth-card__subtitle"><?php esc_html_e('邮箱验证成功', 'aksrt'); ?></p>
|
|
<?php elseif ($verify_mode === 'code') : ?>
|
|
<p class="auth-card__subtitle"><?php esc_html_e('请输入邮箱验证码完成验证', 'aksrt'); ?></p>
|
|
<?php elseif ($verify_mode === 'pending') : ?>
|
|
<p class="auth-card__subtitle"><?php esc_html_e('验证邮件已经发出,请点击邮箱中的链接完成验证', 'aksrt'); ?></p>
|
|
<?php else : ?>
|
|
<p class="auth-card__subtitle"><?php esc_html_e('邮箱验证状态异常,请重新检查链接或重新发送验证邮件', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($verify_error !== '') : ?>
|
|
<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($verify_error); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($verify_success !== '') : ?>
|
|
<div class="alert alert--success" role="alert">
|
|
<span><?php echo esc_html($verify_success); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (($verify_mode === 'completed' || $verify_mode === 'verified') && $redirect_url !== '') : ?>
|
|
<p class="auth-footer-link">
|
|
<a href="<?php echo esc_url($redirect_url); ?>"><?php esc_html_e('立即进入账号', 'aksrt'); ?></a>
|
|
</p>
|
|
<script>
|
|
setTimeout(function(){ window.location.href = <?php echo wp_json_encode($redirect_url); ?>; }, 1800);
|
|
</script>
|
|
<?php elseif ($verify_mode === 'code') : ?>
|
|
<form class="auth-form" method="post" action="">
|
|
<?php wp_nonce_field('aksrt_verify_email', '_verify_email_nonce'); ?>
|
|
<input type="hidden" name="verify_uid" value="<?php echo esc_attr((string) $verify_uid); ?>">
|
|
<input type="hidden" name="vk" value="<?php echo esc_attr($verify_vk); ?>">
|
|
<div class="form-field">
|
|
<label for="verify_email_code"><?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="email_code" id="verify_email_code" inputmode="numeric" maxlength="6" pattern="[0-9]*" autocomplete="one-time-code" required>
|
|
</div>
|
|
</div>
|
|
<?php if ($verify_email !== '') : ?>
|
|
<p class="auth-card__subtitle" style="margin-top:-8px;"><?php echo esc_html(sprintf(__('验证码已发送到 %s', 'aksrt'), $verify_email)); ?></p>
|
|
<?php endif; ?>
|
|
<?php if (function_exists('aksrt_render_captcha')) : ?>
|
|
<?php aksrt_render_captcha('verify_email'); ?>
|
|
<?php endif; ?>
|
|
<button type="submit" name="verify_email_submit" class="btn-primary btn-lg btn-block"><?php esc_html_e('验证并登录', 'aksrt'); ?></button>
|
|
</form>
|
|
<form method="post" action="" style="margin-top:12px;">
|
|
<?php wp_nonce_field('aksrt_verify_email', '_verify_email_nonce'); ?>
|
|
<input type="hidden" name="verify_uid" value="<?php echo esc_attr((string) $verify_uid); ?>">
|
|
<input type="hidden" name="vk" value="<?php echo esc_attr($verify_vk); ?>">
|
|
<?php if (function_exists('aksrt_render_captcha')) : ?>
|
|
<?php aksrt_render_captcha('verify_email'); ?>
|
|
<?php endif; ?>
|
|
<button type="submit" name="verify_email_resend" class="btn-primary btn-lg" style="width:100%;background:transparent;color:var(--color-primary);border:1px solid var(--color-primary);"><?php esc_html_e('重新发送验证码', 'aksrt'); ?></button>
|
|
</form>
|
|
<?php elseif ($verify_mode === 'pending' && $verify_uid > 0 && $verify_vk !== '') : ?>
|
|
<?php
|
|
// method 缺失(历史账号 / meta 被外部清理)→ 回退到设置默认值
|
|
$resend_method = in_array($verify_method, ['link', 'code'], true)
|
|
? $verify_method
|
|
: (class_exists('AKSRT_Settings') ? AKSRT_Settings::registration_verification_method() : 'link');
|
|
?>
|
|
<?php if ($verify_email !== '') : ?>
|
|
<p class="auth-card__subtitle"><?php echo esc_html(sprintf(__('当前待验证邮箱:%s', 'aksrt'), $verify_email)); ?></p>
|
|
<?php endif; ?>
|
|
<form method="post" action="">
|
|
<?php wp_nonce_field('aksrt_verify_email', '_verify_email_nonce'); ?>
|
|
<input type="hidden" name="verify_uid" value="<?php echo esc_attr((string) $verify_uid); ?>">
|
|
<input type="hidden" name="vk" value="<?php echo esc_attr($verify_vk); ?>">
|
|
<?php if (function_exists('aksrt_render_captcha')) : ?>
|
|
<?php aksrt_render_captcha('verify_email'); ?>
|
|
<?php endif; ?>
|
|
<button type="submit" name="verify_email_resend" class="btn-primary btn-lg" style="width:100%;"><?php echo esc_html($resend_method === 'code' ? __('重新发送验证码', 'aksrt') : __('重新发送验证邮件', 'aksrt')); ?></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<p class="auth-footer-link">
|
|
<a href="<?php echo esc_url(aksrt_get_login_url()); ?>"><?php esc_html_e('返回登录', 'aksrt'); ?></a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php
|
|
get_footer();
|