抽出 sign.css,统一全页登录/注册与找回/绑定视觉;中文文案与用户协议契约对齐 Auth_Service;弹层字段与 logo 同步。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
146 lines
6.7 KiB
PHP
146 lines
6.7 KiB
PHP
<?php
|
||
/**
|
||
* Template Name: AKSRT - Bind Account
|
||
* Template Post Type: page
|
||
*
|
||
* Theme auth route template: /bind-account/
|
||
*
|
||
* 第三方登录未匹配账号时的绑定页面
|
||
* 用户输入已有账号密码完成OAuth绑定
|
||
*
|
||
* @package AKSRT
|
||
*/
|
||
|
||
// ============================================
|
||
// 处理绑定请求(POST)
|
||
// ============================================
|
||
$bind_error = '';
|
||
$bind_verify_url = '';
|
||
$oauth_data = null;
|
||
$provider_name = '';
|
||
$obk = '';
|
||
|
||
if (isset($_GET['obk'])) {
|
||
$obk = sanitize_text_field($_GET['obk']);
|
||
$oauth_data = AKSRT_Auth_Service::get_oauth_bind_context($obk);
|
||
}
|
||
|
||
if (! $oauth_data || ! is_array($oauth_data)) {
|
||
// 无效或已过期的OAuth数据
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$bind_error = __('绑定会话已过期,请重新使用第三方登录', 'aksrt');
|
||
}
|
||
} else {
|
||
$provider_name = AKSRT_Auth_Service::get_oauth_provider_name($oauth_data['provider'] ?? '');
|
||
}
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['log'], $_POST['pwd']) && empty($bind_error)) {
|
||
if ($obk === '' && !empty($_POST['obk'])) {
|
||
$obk = sanitize_text_field($_POST['obk']);
|
||
}
|
||
|
||
if ($oauth_data === null && $obk !== '') {
|
||
$oauth_data = AKSRT_Auth_Service::get_oauth_bind_context($obk);
|
||
}
|
||
|
||
$result = AKSRT_Auth_Service::bind_oauth_account($_POST, $oauth_data);
|
||
if (empty($result['success'])) {
|
||
$bind_error = $result['error'] ?? __('绑定失败,请稍后重试', 'aksrt');
|
||
$bind_verify_url = $result['verify_url'] ?? '';
|
||
} else {
|
||
$user = $result['user'];
|
||
$provider = $result['provider'];
|
||
wp_safe_redirect(add_query_arg(['tab' => 'settings', 'oauth_bound' => $provider], aksrt_get_user_center_url()));
|
||
exit;
|
||
}
|
||
}
|
||
|
||
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">
|
||
|
||
<?php if (! $oauth_data || ! is_array($oauth_data)) : ?>
|
||
<!-- 会话过期状态 -->
|
||
<div class="auth-card__expired">
|
||
<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>
|
||
<p><?php echo esc_html(__('绑定会话已过期或无效', 'aksrt')); ?></p>
|
||
<a href="<?php echo esc_url(aksrt_get_login_url()); ?>" class="btn-primary btn-lg auth-card__expired-action">
|
||
<?php esc_html_e('返回登录', 'aksrt'); ?>
|
||
</a>
|
||
</div>
|
||
|
||
<?php else : ?>
|
||
<!-- 正常绑定表单 -->
|
||
|
||
<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>
|
||
<p class="auth-card__subtitle">
|
||
<?php printf(esc_html__('通过 %s 登录,请绑定你的已有账号', 'aksrt'), '<strong>' . esc_html($provider_name) . '</strong>'); ?>
|
||
</p>
|
||
|
||
<?php if (!empty($bind_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($bind_error); ?>
|
||
<?php if (!empty($bind_verify_url)) : ?>
|
||
<a href="<?php echo esc_url($bind_verify_url); ?>"><?php esc_html_e('前往验证邮箱', 'aksrt'); ?></a>
|
||
<?php endif; ?>
|
||
</span>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<form class="auth-form" id="aksrt-bind-form" method="post" action="">
|
||
<?php wp_nonce_field('aksrt_bind', '_bind_nonce'); ?>
|
||
<input type="hidden" name="obk" value="<?php echo esc_attr($obk); ?>">
|
||
<div class="form-field">
|
||
<label for="bind_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="log" id="bind_user_login" autocomplete="username" required>
|
||
</div>
|
||
</div>
|
||
<div class="form-field form-field--pwd">
|
||
<label for="bind_user_pass"><?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="pwd" id="bind_user_pass" autocomplete="current-password" required>
|
||
<button type="button" class="toggle-pwd" data-target="bind_user_pass" 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>
|
||
<?php if (function_exists('aksrt_render_captcha')) : ?>
|
||
<?php aksrt_render_captcha('bind'); ?>
|
||
<?php endif; ?>
|
||
<button type="submit" name="wp-submit" class="btn-primary btn-lg" style="width:100%;margin-top:8px;">
|
||
<?php esc_html_e('绑定并登录', 'aksrt'); ?>
|
||
</button>
|
||
</form>
|
||
|
||
<?php if (class_exists('AKSRT_Settings') ? AKSRT_Settings::registration_enabled() : get_option('users_can_register')) :
|
||
$register_url = aksrt_get_register_url();
|
||
$register_url = add_query_arg('obk', sanitize_text_field($_GET['obk']), $register_url);
|
||
?>
|
||
<p class="auth-footer-link">
|
||
<?php esc_html_e('还没有账号?', 'aksrt'); ?>
|
||
<a href="<?php echo esc_url($register_url); ?>"><?php esc_html_e('注册并绑定账号', 'aksrt'); ?></a>
|
||
</p>
|
||
<?php endif; ?>
|
||
|
||
<?php endif; ?><!-- end 正常绑定表单 -->
|
||
</div>
|
||
</div>
|
||
</main>
|
||
|
||
<?php
|
||
get_footer();
|