Files
wordpress-theme-aksrt/templates/parts/modal-auth.php
T
kate522andClaude Fable 5 8d1b0dacf6 feat(auth): 登录注册找回绑定前台 1:1 壳层/文案/协议
抽出 sign.css,统一全页登录/注册与找回/绑定视觉;中文文案与用户协议契约对齐 Auth_Service;弹层字段与 logo 同步。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 11:14:10 +08:00

266 lines
14 KiB
PHP

<?php
/**
* Modal auth dialog.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (is_user_logged_in()) {
return;
}
$oauth_providers = [];
if (class_exists('AKSRT_OAuth')) {
$oauth_providers = AKSRT_OAuth::get_instance()->get_auth_providers_data();
}
$registration_open = true;
$email_verification = false;
$close_signin = false;
$invite_field_mode = 'hidden';
$invite_field_hint = '';
$invite_prefill = '';
$show_qrcode_tab = false;
if (class_exists('AKSRT_Settings')) {
$registration_open = AKSRT_Settings::registration_enabled();
$email_verification = AKSRT_Settings::registration_requires_email_verification();
$close_signin = AKSRT_Settings::close_signin();
$invite_cfg = AKSRT_Settings::get_invite_registration_config();
$invite_field_mode = (string) ($invite_cfg['register_field'] ?? 'hidden');
$invite_field_hint = $invite_field_mode === 'required'
? (string) ($invite_cfg['must_desc'] ?? '')
: (string) ($invite_cfg['open_desc'] ?? '');
}
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']));
}
foreach ($oauth_providers as $provider) {
if (($provider['name'] ?? '') === 'weixingzh') {
$show_qrcode_tab = true;
break;
}
}
$site_name = get_bloginfo('name');
$reset_url = function_exists('aksrt_get_reset_password_url') ? aksrt_get_reset_password_url() : wp_lostpassword_url();
$agreement = function_exists('aksrt_get_auth_agreement_view')
? aksrt_get_auth_agreement_view()
: ['enabled' => true, 'required' => true, 'label_html' => esc_html__('我已阅读并同意用户协议', 'aksrt'), 'field_name' => 'agree_terms'];
$logo_url = class_exists('AKSRT_Settings') ? AKSRT_Settings::user_logo_url() : '';
?>
<div class="aksrt-modal-auth" id="aksrt-modal-auth" aria-hidden="true" role="dialog" aria-modal="true" aria-label="<?php esc_attr_e('登录', 'aksrt'); ?>">
<div class="aksrt-modal-auth__overlay"></div>
<div class="aksrt-modal-auth__card">
<button type="button" class="aksrt-modal-auth__close" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>">
<i class="fas fa-times"></i>
</button>
<div class="aksrt-modal-auth__header">
<?php if ($logo_url) : ?>
<div class="aksrt-modal-auth__logo aksrt-modal-auth__logo--image"><img src="<?php echo esc_url($logo_url); ?>" alt=""></div>
<?php else : ?>
<div class="aksrt-modal-auth__logo"><?php echo esc_html(mb_substr($site_name, 0, 2)); ?></div>
<?php endif; ?>
<h2 class="aksrt-modal-auth__title"><?php echo esc_html($site_name); ?></h2>
</div>
<div class="aksrt-modal-auth__tabs" role="tablist">
<button type="button" class="aksrt-modal-auth__tab is-active" data-tab="login" role="tab" aria-selected="true">
<?php esc_html_e('登录', 'aksrt'); ?>
</button>
<?php if ($registration_open) : ?>
<button type="button" class="aksrt-modal-auth__tab" data-tab="register" role="tab" aria-selected="false">
<?php esc_html_e('注册', 'aksrt'); ?>
</button>
<?php endif; ?>
<?php if ($show_qrcode_tab) : ?>
<button type="button" class="aksrt-modal-auth__tab" data-tab="qrcode" role="tab" aria-selected="false">
<?php esc_html_e('扫码登录', 'aksrt'); ?>
</button>
<?php endif; ?>
</div>
<div class="aksrt-modal-auth__panel is-active" data-panel="login">
<?php if ($close_signin) : ?>
<div class="aksrt-modal-auth__error is-success" id="aksrt-modal-login-error">
<?php esc_html_e('当前已关闭账密登录,请使用下方第三方登录方式。', 'aksrt'); ?>
</div>
<?php else : ?>
<form class="aksrt-modal-auth__form" id="aksrt-modal-login-form">
<div class="aksrt-modal-auth__error" id="aksrt-modal-login-error" hidden></div>
<?php wp_nonce_field('aksrt_login', '_login_nonce'); ?>
<div class="aksrt-modal-auth__field">
<label for="modal-login-user"><?php esc_html_e('邮箱 / 用户名', 'aksrt'); ?></label>
<input type="text" id="modal-login-user" name="log" autocomplete="username" required placeholder="<?php esc_attr_e('请输入邮箱或用户名', 'aksrt'); ?>">
</div>
<div class="aksrt-modal-auth__field">
<label for="modal-login-pass"><?php esc_html_e('密码', 'aksrt'); ?></label>
<div class="aksrt-modal-auth__pass-wrap">
<input type="password" id="modal-login-pass" name="pwd" autocomplete="current-password" required placeholder="<?php esc_attr_e('请输入密码', 'aksrt'); ?>">
<button type="button" class="aksrt-modal-auth__pass-toggle" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>">
<i class="far fa-eye"></i>
</button>
</div>
</div>
<?php if (function_exists('aksrt_render_captcha')) : ?>
<?php aksrt_render_captcha('login'); ?>
<?php endif; ?>
<div class="aksrt-modal-auth__actions">
<a href="<?php echo esc_url($reset_url); ?>" class="aksrt-modal-auth__link"><?php esc_html_e('忘记密码?', 'aksrt'); ?></a>
</div>
<button type="submit" class="aksrt-modal-auth__submit">
<span><?php esc_html_e('登录', 'aksrt'); ?></span>
<i class="fas fa-spinner fa-spin" hidden></i>
</button>
</form>
<?php endif; ?>
</div>
<?php if ($registration_open) : ?>
<div class="aksrt-modal-auth__panel" data-panel="register">
<form class="aksrt-modal-auth__form" id="aksrt-modal-register-form">
<div class="aksrt-modal-auth__error" id="aksrt-modal-register-error" hidden></div>
<?php wp_nonce_field('aksrt_register', '_register_nonce'); ?>
<div class="aksrt-modal-auth__field">
<label for="modal-reg-user"><?php esc_html_e('用户名', 'aksrt'); ?></label>
<input type="text" id="modal-reg-user" name="user_login" autocomplete="username" required placeholder="<?php esc_attr_e('请输入用户名', 'aksrt'); ?>">
</div>
<div class="aksrt-modal-auth__field">
<label for="modal-reg-email"><?php esc_html_e('邮箱', 'aksrt'); ?></label>
<input type="email" id="modal-reg-email" name="user_email" autocomplete="email" required placeholder="<?php esc_attr_e('请输入邮箱', 'aksrt'); ?>">
</div>
<div class="aksrt-modal-auth__field">
<label for="modal-reg-pass"><?php esc_html_e('密码', 'aksrt'); ?></label>
<div class="aksrt-modal-auth__pass-wrap">
<input type="password" id="modal-reg-pass" name="user_pass" autocomplete="new-password" required minlength="6" placeholder="<?php esc_attr_e('至少 6 位字符', 'aksrt'); ?>">
<button type="button" class="aksrt-modal-auth__pass-toggle" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>">
<i class="far fa-eye"></i>
</button>
</div>
</div>
<div class="aksrt-modal-auth__field">
<label for="modal-reg-pass-confirm"><?php esc_html_e('确认密码', 'aksrt'); ?></label>
<div class="aksrt-modal-auth__pass-wrap">
<input type="password" id="modal-reg-pass-confirm" name="user_pass_confirm" autocomplete="new-password" required minlength="6" placeholder="<?php esc_attr_e('请再次输入密码', 'aksrt'); ?>">
<button type="button" class="aksrt-modal-auth__pass-toggle" aria-label="<?php esc_attr_e('显示或隐藏密码', 'aksrt'); ?>">
<i class="far fa-eye"></i>
</button>
</div>
</div>
<?php if ($invite_field_mode !== 'hidden') : ?>
<div class="aksrt-modal-auth__field">
<label for="modal-reg-invite">
<?php esc_html_e('邀请码', 'aksrt'); ?>
<?php if ($invite_field_mode === 'optional') : ?>
<small><?php esc_html_e('(选填)', 'aksrt'); ?></small>
<?php endif; ?>
</label>
<input type="text" id="modal-reg-invite" name="invite_code" value="<?php echo esc_attr($invite_prefill); ?>" <?php echo $invite_field_mode === 'required' ? 'required' : ''; ?> placeholder="<?php esc_attr_e('请输入邀请码', 'aksrt'); ?>">
<?php if ($invite_field_hint !== '') : ?>
<p class="aksrt-modal-auth__hint"><?php echo wp_kses_post($invite_field_hint); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if (!empty($agreement['enabled'])) : ?>
<label class="aksrt-modal-auth__checkbox aksrt-modal-auth__agreement">
<input type="checkbox" name="<?php echo esc_attr($agreement['field_name']); ?>" value="1" <?php echo !empty($agreement['required']) ? 'required' : ''; ?>>
<span><?php echo $agreement['label_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
</label>
<?php endif; ?>
<?php if ($email_verification) : ?>
<p class="aksrt-modal-auth__hint"><?php esc_html_e('注册后需要完成邮箱验证。', 'aksrt'); ?></p>
<?php endif; ?>
<?php if (function_exists('aksrt_render_captcha')) : ?>
<?php aksrt_render_captcha('register'); ?>
<?php endif; ?>
<button type="submit" class="aksrt-modal-auth__submit">
<span><?php esc_html_e('注册', 'aksrt'); ?></span>
<i class="fas fa-spinner fa-spin" hidden></i>
</button>
</form>
</div>
<?php endif; ?>
<?php if ($show_qrcode_tab) : ?>
<div class="aksrt-modal-auth__panel" data-panel="qrcode">
<div class="aksrt-modal-auth__form">
<div class="aksrt-modal-auth__error" id="aksrt-modal-qrcode-error" hidden></div>
<div class="aksrt-modal-auth__qr-code"></div>
<p class="aksrt-modal-auth__hint"><?php esc_html_e('请使用微信扫码,在手机上完成登录。', 'aksrt'); ?></p>
</div>
</div>
<?php endif; ?>
<?php if (!empty($oauth_providers)) : ?>
<div class="aksrt-modal-auth__divider">
<span><?php esc_html_e('其他登录方式', 'aksrt'); ?></span>
</div>
<div class="aksrt-modal-auth__oauth">
<?php foreach ($oauth_providers as $provider) :
$provider_name = (string) ($provider['name'] ?? '');
$label = $provider['label'] ?? $provider_name;
$url = $provider['url'] ?? '#';
$icon = $provider['icon'] ?? '';
?>
<a
href="<?php echo esc_url($url); ?>"
class="aksrt-modal-auth__oauth-btn social-login-item <?php echo esc_attr($provider_name); ?>"
data-provider="<?php echo esc_attr($provider_name); ?>"
title="<?php echo esc_attr($label); ?>"
>
<?php echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="aksrt-modal-auth__footer">
<span class="aksrt-modal-auth__footer-text" data-for="login">
<?php if ($registration_open) : ?>
<?php esc_html_e('还没有账号?', 'aksrt'); ?>
<button type="button" class="aksrt-modal-auth__switch" data-switch="register"><?php esc_html_e('立即注册', 'aksrt'); ?></button>
<?php elseif ($show_qrcode_tab) : ?>
<?php esc_html_e('使用扫码登录?', 'aksrt'); ?>
<button type="button" class="aksrt-modal-auth__switch" data-switch="qrcode"><?php esc_html_e('打开扫码登录', 'aksrt'); ?></button>
<?php endif; ?>
</span>
<?php if ($registration_open) : ?>
<span class="aksrt-modal-auth__footer-text" data-for="register" hidden>
<?php esc_html_e('已有账号?', 'aksrt'); ?>
<button type="button" class="aksrt-modal-auth__switch" data-switch="login"><?php esc_html_e('立即登录', 'aksrt'); ?></button>
</span>
<?php endif; ?>
<?php if ($show_qrcode_tab) : ?>
<span class="aksrt-modal-auth__footer-text" data-for="qrcode" hidden>
<?php esc_html_e('改用密码登录?', 'aksrt'); ?>
<button type="button" class="aksrt-modal-auth__switch" data-switch="login"><?php esc_html_e('返回登录', 'aksrt'); ?></button>
</span>
<?php endif; ?>
</div>
</div>
</div>