登录注册体系的源码级硬切换
This commit is contained in:
+28
-254
@@ -1,268 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Modal auth dialog.
|
||||
* Shared authentication modal shell.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (is_user_logged_in()) {
|
||||
return;
|
||||
if (is_user_logged_in() || (class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::close_sign())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$oauth_providers = [];
|
||||
if (class_exists('\AKSRT\Auth\OAuth')) {
|
||||
$oauth_providers = \AKSRT\Auth\OAuth::get_instance()->get_auth_providers_data();
|
||||
$modal_ui = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::modal_ui() : [];
|
||||
$images = $modal_ui['background'] ?? [];
|
||||
if (is_string($images)) {
|
||||
$images = array_filter(array_map('absint', explode(',', $images)));
|
||||
}
|
||||
|
||||
$registration_open = true;
|
||||
$email_verification = false;
|
||||
$close_signin = false;
|
||||
$ref_field_mode = 'hidden';
|
||||
$ref_field_hint = '';
|
||||
$ref_prefill = '';
|
||||
$show_qrcode_tab = false;
|
||||
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
$registration_open = \AKSRT\Settings\Settings::registration_enabled();
|
||||
if (method_exists('\AKSRT\Settings\Settings', 'close_signup') && \AKSRT\Settings\Settings::close_signup()) {
|
||||
$registration_open = false;
|
||||
}
|
||||
$email_verification = \AKSRT\Settings\Settings::registration_requires_email_verification();
|
||||
$close_signin = \AKSRT\Settings\Settings::close_signin();
|
||||
|
||||
$ref_cfg = \AKSRT\Settings\Settings::get_referral_registration_settings();
|
||||
$ref_field_mode = !empty($ref_cfg['enabled']) ? (string) ($ref_cfg['register_field'] ?? 'hidden') : 'hidden';
|
||||
$ref_field_hint = $ref_field_mode === 'required'
|
||||
? (string) ($ref_cfg['required_desc'] ?? '')
|
||||
: (string) ($ref_cfg['open_desc'] ?? '');
|
||||
$image_url = '';
|
||||
if (is_array($images) && $images) {
|
||||
$image_url = (string) wp_get_attachment_url((int) $images[array_rand($images)]);
|
||||
}
|
||||
|
||||
if (!empty($_COOKIE['aksrt_referral'])) {
|
||||
$ref_prefill = sanitize_key(wp_unslash($_COOKIE['aksrt_referral']));
|
||||
} elseif (!empty($_GET['ref'])) {
|
||||
$ref_prefill = sanitize_key(wp_unslash($_GET['ref']));
|
||||
}
|
||||
|
||||
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\Settings') ? \AKSRT\Settings\Settings::user_logo_url() : '';
|
||||
$auto = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::sign_modal_auto() : ['enabled' => false, 'waiting' => 5, 'expires' => 1];
|
||||
$wechat = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_weixingzh_settings() : [];
|
||||
$initial_tab = !empty($wechat['priority']) && class_exists('\AKSRT\Auth\WeixinGzh') && \AKSRT\Auth\WeixinGzh::is_enabled() ? 'oauth' : 'signin';
|
||||
$aksrt_auth_context = [
|
||||
'surface' => 'modal',
|
||||
'tab' => $initial_tab,
|
||||
'show_logo' => !empty($modal_ui['show_logo']),
|
||||
'redirect_to' => home_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="fa fas fa-times"></i>
|
||||
</button>
|
||||
|
||||
<div class="aksrt-modal-auth__header modal-colorful-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="fa fas 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="fa 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="fa fas 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="fa fas fa-eye"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($ref_field_mode !== 'hidden') : ?>
|
||||
<div class="aksrt-modal-auth__field">
|
||||
<label for="modal-reg-ref">
|
||||
<?php esc_html_e('推广码', 'aksrt'); ?>
|
||||
<?php if ($ref_field_mode === 'optional') : ?>
|
||||
<small><?php esc_html_e('(选填)', 'aksrt'); ?></small>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<input type="text" id="modal-reg-ref" name="ref" maxlength="12" value="<?php echo esc_attr($ref_prefill); ?>" <?php echo $ref_field_mode === 'required' ? 'required' : ''; ?> placeholder="<?php esc_attr_e('请输入推广码', 'aksrt'); ?>">
|
||||
<?php if ($ref_field_hint !== '') : ?>
|
||||
<p class="aksrt-modal-auth__hint"><?php echo wp_kses_post($ref_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="fa 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 id="u_sign" class="aksrt-auth-modal<?php echo $image_url !== '' ? ' has-sign-img' : ''; ?>" aria-hidden="true" role="dialog" aria-modal="true" data-auth-modal data-auto="<?php echo !empty($auto['enabled']) ? '1' : '0'; ?>" data-auto-wait="<?php echo esc_attr((string) $auto['waiting']); ?>" data-auto-expires="<?php echo esc_attr((string) $auto['expires']); ?>">
|
||||
<div class="auth-modal-backdrop" data-auth-close></div>
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<button type="button" class="auth-modal-close" data-auth-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times"></i></button>
|
||||
<?php if ($image_url !== '') : ?><div class="sign-img" style="background-image:url('<?php echo esc_url($image_url); ?>')"></div><?php endif; ?>
|
||||
<?php require get_template_directory() . '/templates/parts/auth-content.php'; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user