346 lines
20 KiB
PHP
346 lines
20 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: AKSRT - 登录/注册
|
|
* Template Post Type: page
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
@session_start();
|
|
|
|
$route_tab = function_exists('aksrt_get_auth_tab') ? aksrt_get_auth_tab() : 'login';
|
|
$requested_tab = isset($_GET['tab']) ? sanitize_text_field(wp_unslash((string) $_GET['tab'])) : '';
|
|
$tab_aliases = [
|
|
'login' => 'signin',
|
|
'signin' => 'signin',
|
|
'register' => 'signup',
|
|
'signup' => 'signup',
|
|
];
|
|
$tab_source = $requested_tab !== '' ? $requested_tab : $route_tab;
|
|
$tab = $tab_aliases[$tab_source] ?? 'signin';
|
|
$redirect_to = !empty($_GET['redirect_to']) ? esc_url_raw(wp_unslash((string) $_GET['redirect_to'])) : home_url();
|
|
$registration_open = class_exists('AKSRT_Settings') && AKSRT_Settings::registration_enabled();
|
|
|
|
$titles = [
|
|
'signin' => __('用户登录', 'aksrt'),
|
|
'signup' => __('用户注册', 'aksrt'),
|
|
];
|
|
$page_title = ($titles[$tab] ?? __('登录 / 注册', 'aksrt')) . ' - ' . get_bloginfo('name');
|
|
|
|
$interim = isset($_REQUEST['interim-login']);
|
|
|
|
// 搂4.1 Defense-in-depth: redirect out when close_sign is active (backup of auth router gate)
|
|
if (class_exists('AKSRT_Settings') && AKSRT_Settings::close_sign() && !is_user_logged_in() && !$interim) {
|
|
wp_safe_redirect(home_url('/'), 302);
|
|
exit;
|
|
}
|
|
|
|
// §4.1 close_signin: password login disabled — force signin tab to show social-only message
|
|
$close_signin = class_exists('AKSRT_Settings') ? AKSRT_Settings::close_signin() : false;
|
|
if ($close_signin && $tab === 'signin') {
|
|
// Don't allow password form submission
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
}
|
|
|
|
$user_id = get_current_user_id();
|
|
if ($user_id) {
|
|
if ($interim && is_super_admin()) {
|
|
echo '<!DOCTYPE HTML><html><body class="login interim-login-success"><div style="padding:60px 0;text-align:center;color:#1a88fd;">' . esc_html__('登录成功', 'aksrt') . '</div></body></html>';
|
|
exit;
|
|
}
|
|
wp_safe_redirect($redirect_to);
|
|
exit;
|
|
}
|
|
|
|
if ($tab === 'signup' && !$registration_open) {
|
|
$tab = 'signin';
|
|
}
|
|
|
|
remove_action('wp_footer', 'aksrt_render_footer_tabbar', 20);
|
|
remove_action('wp_footer', 'aksrt_render_float_buttons', 30);
|
|
|
|
$background_html = '';
|
|
$sign_ui = class_exists('AKSRT_Settings') ? AKSRT_Settings::sign_page_ui() : [];
|
|
$card_position = $sign_ui['card_position'] ?? 'center';
|
|
$sign_show_logo = $sign_ui['show_logo'] ?? true;
|
|
$sign_show_header = $sign_ui['show_header'] ?? true;
|
|
$sign_theme_mode = $sign_ui['theme_mode'] ?? 'default';
|
|
if (class_exists('AKSRT_Settings')) {
|
|
$bg_ids = $sign_ui['background'] ?? [];
|
|
if (is_array($bg_ids) && !empty($bg_ids)) {
|
|
$bg_url = wp_get_attachment_url((int) $bg_ids[array_rand($bg_ids)]);
|
|
if ($bg_url) {
|
|
$background_html = '<div class="sign-bg" style="background-image:url(' . esc_url($bg_url) . ');"></div>';
|
|
}
|
|
} elseif (is_string($bg_ids) && $bg_ids !== '') {
|
|
// BC: comma-separated string from old storage
|
|
$ids = array_filter(array_map('absint', explode(',', $bg_ids)));
|
|
if (!empty($ids)) {
|
|
$bg_url = wp_get_attachment_url($ids[array_rand($ids)]);
|
|
if ($bg_url) {
|
|
$background_html = '<div class="sign-bg" style="background-image:url(' . esc_url($bg_url) . ');"></div>';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$login_error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['log'], $_POST['pwd']) && $tab === 'signin') {
|
|
if (class_exists('AKSRT_Auth_Service')) {
|
|
$result = AKSRT_Auth_Service::login_user($_POST, false);
|
|
if (empty($result['success'])) {
|
|
$login_error = $result['error'] ?? __('登录失败', 'aksrt');
|
|
} else {
|
|
wp_safe_redirect($result['redirect'] ?? home_url('/'));
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
$register_error = '';
|
|
$register_success = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['user_login'], $_POST['user_email']) && $tab === 'signup') {
|
|
if (class_exists('AKSRT_Auth_Service')) {
|
|
$result = AKSRT_Auth_Service::register_user($_POST, ['oauth_bind_data' => null, 'obk' => '']);
|
|
if (!empty($result['success'])) {
|
|
if (!empty($result['verification_required'])) {
|
|
$register_success = sprintf(
|
|
'%s <a href="%s">%s</a>',
|
|
esc_html($result['message'] ?? __('Registration successful. Please complete email verification.', 'aksrt')),
|
|
esc_url($result['verify_url'] ?? ''),
|
|
esc_html__('前往验证', 'aksrt')
|
|
);
|
|
} else {
|
|
$register_success = sprintf(
|
|
__('Registration successful. Please continue on the <a href="%s">login page</a>.', 'aksrt'),
|
|
esc_url(aksrt_get_login_url())
|
|
);
|
|
}
|
|
} else {
|
|
$register_error = $result['error'] ?? __('注册失败', 'aksrt');
|
|
}
|
|
}
|
|
}
|
|
|
|
$invite_prefill = '';
|
|
if (!empty($_GET['invite'])) {
|
|
$invite_prefill = sanitize_key(wp_unslash($_GET['invite']));
|
|
} elseif (!empty($_COOKIE['aksrt_invite'])) {
|
|
$invite_prefill = sanitize_key(wp_unslash($_COOKIE['aksrt_invite']));
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="<?php echo esc_attr(str_replace('_', '-', get_bloginfo('language'))); ?>">
|
|
<head>
|
|
<meta charset="<?php bloginfo('charset'); ?>">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
|
|
<meta name="robots" content="noindex, nofollow">
|
|
<title><?php echo esc_html($page_title); ?></title>
|
|
<?php wp_head(); ?>
|
|
<style>
|
|
.sign-page{min-height:100vh;display:flex;align-items:center;justify-content:center;position:relative;padding:70px 16px 40px}
|
|
.sign-bg{position:fixed;inset:0;background-repeat:no-repeat;background-size:cover;background-position:center;z-index:0}
|
|
.sign-card{position:relative;z-index:1;width:100%;max-width:420px;background:var(--main-bg-color,#fff);border-radius:var(--main-radius,8px);box-shadow:0 0 10px var(--main-shadow,rgba(116,116,116,0.08));padding:30px 35px}
|
|
.sign-card--left{margin-right:auto}
|
|
.sign-card--right{margin-left:auto}
|
|
.sign-card--center{margin:0 auto}
|
|
.sign-logo{text-align:center;margin-bottom:20px}
|
|
.sign-logo img{height:36px}
|
|
.sign-logo__text{display:inline-flex;align-items:center;justify-content:center;width:48px;height:48px;border-radius:12px;background:var(--focus-color,#f04494);color:#fff;font-size:18px;font-weight:700;text-decoration:none}
|
|
.sign-tabs{display:flex;border-bottom:2px solid var(--main-border-color,rgba(50,50,50,0.06));margin-bottom:20px}
|
|
.sign-tab{flex:1;padding:10px 0;border:none;background:none;font-size:15px;cursor:pointer;color:var(--muted-color,#777);border-bottom:2px solid transparent;margin-bottom:-2px;transition:all .2s;text-align:center;font-weight:500}
|
|
.sign-tab.is-active{color:var(--focus-color,#f04494);border-bottom-color:var(--focus-color,#f04494);font-weight:600}
|
|
.sign-tab:hover{color:var(--focus-color,#f04494)}
|
|
.sign-panel{display:none}
|
|
.sign-panel.is-active{display:block}
|
|
.sign-error{background:rgba(239,68,68,0.08);border:1px solid rgba(239,68,68,0.2);border-radius:var(--main-radius,8px);padding:10px 14px;font-size:13px;color:#ef4444;margin-bottom:16px}
|
|
.sign-success{background:rgba(16,185,129,0.08);border:1px solid rgba(16,185,129,0.2);border-radius:var(--main-radius,8px);padding:10px 14px;font-size:13px;color:#10b981;margin-bottom:16px}
|
|
.sign-form{display:flex;flex-direction:column;gap:16px}
|
|
.sign-form .form-field{display:flex;flex-direction:column;gap:6px}
|
|
.sign-form label{font-size:14px;font-weight:500;color:var(--main-color,#4e5358)}
|
|
.sign-form .input-wrap{position:relative}
|
|
.sign-form .input-wrap input{width:100%;height:44px;padding:0 14px;border:1px solid transparent;background:var(--body-bg-color,#f5f6f7);border-radius:var(--main-radius,8px);font-size:14px;color:var(--key-color,#333);transition:border-color .15s}
|
|
.sign-form .input-wrap input:focus{outline:none;border-color:var(--focus-color,#f04494);box-shadow:0 0 2px 3px var(--focus-shadow-color,rgba(253,83,161,0.4))}
|
|
.sign-form .toggle-pwd{position:absolute;right:10px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;color:var(--muted-2-color,#999);padding:4px}
|
|
.sign-form .form-row-between{display:flex;align-items:center;justify-content:space-between;font-size:13px}
|
|
.sign-form .form-row-between a{color:var(--focus-color,#f04494)}
|
|
.sign-form .form-row-between label{display:flex;align-items:center;gap:6px;cursor:pointer;font-size:13px;color:var(--muted-color,#777)}
|
|
.sign-form .btn-submit{width:100%;height:44px;border:none;border-radius:var(--main-radius,8px);background:var(--focus-color,#f04494);color:#fff;font-size:15px;font-weight:600;cursor:pointer;transition:opacity .15s}
|
|
.sign-form .btn-submit:hover{opacity:.85}
|
|
.sign-form .btn-submit:disabled{opacity:.5;cursor:not-allowed}
|
|
.sign-hint{margin:0;font-size:13px;color:var(--muted-color,#777)}
|
|
.sign-terms{display:flex;align-items:flex-start;gap:8px;font-size:13px;cursor:pointer;color:var(--muted-color,#777)}
|
|
.sign-footer{text-align:center;margin-top:20px;font-size:14px;color:var(--muted-color,#777)}
|
|
.sign-footer a{color:var(--focus-color,#f04494)}
|
|
.sign-footer-bar{position:fixed;bottom:0;left:0;right:0;text-align:center;padding:10px;font-size:12px;color:var(--muted-2-color,#999);z-index:1}
|
|
@media(max-width:480px){.sign-card{padding:24px 20px}}
|
|
</style>
|
|
</head>
|
|
<body <?php body_class('page-template-user-sign' . ($sign_theme_mode !== 'default' ? ' sign-theme-' . esc_attr($sign_theme_mode) : '')); ?>>
|
|
<?php echo $background_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<main class="sign-page">
|
|
<div class="sign-card sign-card--<?php echo esc_attr($card_position); ?>">
|
|
<?php if ($sign_show_logo) : ?>
|
|
<div class="sign-logo">
|
|
<?php $logo_url = class_exists('AKSRT_Settings') ? AKSRT_Settings::user_logo_url() : ''; ?>
|
|
<?php if ($logo_url) : ?>
|
|
<a href="<?php echo esc_url(home_url('/')); ?>"><img src="<?php echo esc_url($logo_url); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>"></a>
|
|
<?php else : ?>
|
|
<a href="<?php echo esc_url(home_url('/')); ?>" class="sign-logo__text"><?php echo esc_html(mb_substr(get_bloginfo('name'), 0, 2)); ?></a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($sign_show_header) : ?>
|
|
<div class="sign-tabs">
|
|
<button type="button" class="sign-tab<?php echo $tab === 'signin' ? ' is-active' : ''; ?>" data-sign-tab="signin"><?php esc_html_e('登录', 'aksrt'); ?></button>
|
|
<?php if ($registration_open) : ?>
|
|
<button type="button" class="sign-tab<?php echo $tab === 'signup' ? ' is-active' : ''; ?>" data-sign-tab="signup"><?php esc_html_e('注册', 'aksrt'); ?></button>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="sign-panel<?php echo $tab === 'signin' ? ' is-active' : ''; ?>" data-sign-panel="signin">
|
|
<?php if ($login_error) : ?><div class="sign-error"><?php echo esc_html($login_error); ?></div><?php endif; ?>
|
|
<?php if ($close_signin) : ?>
|
|
<div class="sign-notice" style="padding:16px;text-align:center;color:var(--muted-2-color,#666);">
|
|
<?php esc_html_e('This site currently supports third-party account sign-in only. Please use one of the social login buttons below.', 'aksrt'); ?>
|
|
</div>
|
|
<?php else : ?>
|
|
<form class="sign-form" id="sign-login-form" method="post" action="">
|
|
<?php wp_nonce_field('aksrt_login', '_login_nonce'); ?>
|
|
<div class="form-field">
|
|
<label for="sign-user-login"><?php esc_html_e('Email / Username', 'aksrt'); ?></label>
|
|
<div class="input-wrap"><input type="text" name="log" id="sign-user-login" autocomplete="username" required placeholder="<?php esc_attr_e('Please enter your email or username', 'aksrt'); ?>"></div>
|
|
</div>
|
|
<div class="form-field">
|
|
<label for="sign-user-pass"><?php esc_html_e('密码', 'aksrt'); ?></label>
|
|
<div class="input-wrap">
|
|
<input type="password" name="pwd" id="sign-user-pass" autocomplete="current-password" required>
|
|
<button type="button" class="toggle-pwd" data-target="sign-user-pass"><i class="fas fa-eye"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="form-row-between">
|
|
<label><input type="checkbox" name="rememberme" value="forever"> <?php esc_html_e('Remember me', 'aksrt'); ?></label>
|
|
<a href="<?php echo esc_url(aksrt_get_reset_password_url()); ?>"><?php esc_html_e('Forgot password?', 'aksrt'); ?></a>
|
|
</div>
|
|
<?php if (function_exists('aksrt_render_captcha')) aksrt_render_captcha('login'); ?>
|
|
<input type="hidden" name="redirect_to" value="<?php echo esc_url($redirect_to); ?>">
|
|
<button type="submit" class="btn-submit"><?php esc_html_e('登录', 'aksrt'); ?></button>
|
|
</form>
|
|
<?php endif; // close_signin gate ?>
|
|
<?php if (class_exists('AKSRT_OAuth')) : ?>
|
|
<?php $social = AKSRT_OAuth::get_instance()->render_social_buttons(); ?>
|
|
<?php if ($social) echo '<div style="margin-top:20px;">' . $social . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
<?php endif; ?>
|
|
<?php if ($registration_open) : ?>
|
|
<div class="sign-footer"><?php esc_html_e('Don\'t have an account yet?', 'aksrt'); ?> <a href="#" data-sign-switch="signup"><?php esc_html_e('Register now', 'aksrt'); ?></a></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ($registration_open) : ?>
|
|
<div class="sign-panel<?php echo $tab === 'signup' ? ' is-active' : ''; ?>" data-sign-panel="signup">
|
|
<?php if ($register_error) : ?><div class="sign-error"><?php echo esc_html($register_error); ?></div><?php endif; ?>
|
|
<?php if ($register_success) : ?><div class="sign-success"><?php echo wp_kses($register_success, ['a' => ['href' => []]]); ?></div><?php endif; ?>
|
|
<form class="sign-form" id="sign-register-form" method="post" action="" novalidate>
|
|
<?php wp_nonce_field('aksrt_register', '_register_nonce'); ?>
|
|
<div class="form-field">
|
|
<label for="sign-reg-login"><?php esc_html_e('Username', 'aksrt'); ?></label>
|
|
<div class="input-wrap"><input type="text" name="user_login" id="sign-reg-login" autocomplete="username" required placeholder="<?php esc_attr_e('请输入用户名', 'aksrt'); ?>"></div>
|
|
</div>
|
|
<div class="form-field">
|
|
<label for="sign-reg-email"><?php esc_html_e('Email Address', 'aksrt'); ?></label>
|
|
<div class="input-wrap"><input type="email" name="user_email" id="sign-reg-email" autocomplete="email" required placeholder="<?php esc_attr_e('Please enter your email', 'aksrt'); ?>"></div>
|
|
</div>
|
|
<div class="form-field">
|
|
<label for="sign-reg-pass"><?php esc_html_e('登录密码', 'aksrt'); ?></label>
|
|
<div class="input-wrap">
|
|
<input type="password" name="user_pass" id="sign-reg-pass" autocomplete="new-password" required minlength="6">
|
|
<button type="button" class="toggle-pwd" data-target="sign-reg-pass"><i class="fas fa-eye"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="form-field">
|
|
<label for="sign-reg-pass2"><?php esc_html_e('确认密码', 'aksrt'); ?></label>
|
|
<div class="input-wrap">
|
|
<input type="password" name="user_pass_confirm" id="sign-reg-pass2" autocomplete="new-password" required minlength="6">
|
|
<button type="button" class="toggle-pwd" data-target="sign-reg-pass2"><i class="fas fa-eye"></i></button>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
$invite_cfg = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_invite_registration_config() : null;
|
|
if ($invite_cfg && ($invite_cfg['register_field'] ?? 'hidden') !== 'hidden') {
|
|
$mode = (string) $invite_cfg['register_field'];
|
|
$invit_hint = $mode === 'required'
|
|
? (string) ($invite_cfg['must_desc'] ?? '')
|
|
: (string) ($invite_cfg['open_desc'] ?? '');
|
|
?>
|
|
<div class="form-field">
|
|
<label for="sign-invite"><?php esc_html_e('邀请码', 'aksrt'); ?><?php echo $mode === 'optional' ? ' <small style="color:var(--muted-color);">(' . esc_html__('选填', 'aksrt') . ')</small>' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label>
|
|
<div class="input-wrap"><input type="text" name="invite_code" id="sign-invite" maxlength="32" autocomplete="off" value="<?php echo esc_attr($invite_prefill); ?>" <?php echo $mode === 'required' ? 'required' : ''; ?>></div>
|
|
<?php if ($invit_hint !== '') : ?>
|
|
<p class="sign-hint"><?php echo wp_kses_post($invit_hint); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php } ?>
|
|
<label class="sign-terms">
|
|
<input type="checkbox" name="agree_terms" value="1" required>
|
|
<span><?php esc_html_e('I agree to the Terms of Service', 'aksrt'); ?></span>
|
|
</label>
|
|
<?php if (class_exists('AKSRT_Settings') && AKSRT_Settings::registration_requires_email_verification()) : ?>
|
|
<p class="sign-hint"><?php esc_html_e('Email verification is required after registration.', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
<?php if (function_exists('aksrt_render_captcha')) aksrt_render_captcha('register'); ?>
|
|
<button type="submit" class="btn-submit"><?php esc_html_e('注册', 'aksrt'); ?></button>
|
|
</form>
|
|
<div class="sign-footer"><?php esc_html_e('Already have an account?', 'aksrt'); ?> <a href="#" data-sign-switch="signin"><?php esc_html_e('Sign in now', 'aksrt'); ?></a></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<script>
|
|
(function(){
|
|
document.querySelectorAll('[data-sign-tab]').forEach(function(tab){
|
|
tab.addEventListener('click',function(){
|
|
var target=this.getAttribute('data-sign-tab');
|
|
this.parentElement.querySelectorAll('.sign-tab').forEach(function(t){t.classList.remove('is-active');});
|
|
this.classList.add('is-active');
|
|
var card=this.closest('.sign-card');
|
|
card.querySelectorAll('.sign-panel[data-sign-panel]').forEach(function(p){p.classList.remove('is-active');});
|
|
var panel=card.querySelector('[data-sign-panel="'+target+'"]');
|
|
if(panel)panel.classList.add('is-active');
|
|
});
|
|
});
|
|
document.querySelectorAll('[data-sign-switch]').forEach(function(link){
|
|
link.addEventListener('click',function(e){
|
|
e.preventDefault();
|
|
var target=this.getAttribute('data-sign-switch');
|
|
var btn=document.querySelector('[data-sign-tab="'+target+'"]');
|
|
if(btn)btn.click();
|
|
});
|
|
});
|
|
document.querySelectorAll('.toggle-pwd').forEach(function(btn){
|
|
btn.addEventListener('click',function(){
|
|
var input=document.getElementById(this.getAttribute('data-target'));
|
|
if(!input)return;
|
|
var isPw=input.type==='password';
|
|
input.type=isPw?'text':'password';
|
|
this.querySelector('i').className=isPw?'fas fa-eye-slash':'fas fa-eye';
|
|
});
|
|
});
|
|
})();
|
|
</script>
|
|
|
|
<?php if (!$interim) : ?>
|
|
<div class="sign-footer-bar">
|
|
<?php
|
|
$footer_text = $sign_ui['footer'] ?? '';
|
|
echo $footer_text ? wp_kses_post($footer_text) : '© ' . date('Y') . ' ' . esc_html(get_bloginfo('name'));
|
|
?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php wp_footer(); ?>
|
|
</body>
|
|
</html>
|