fix(captcha): 1:1 align bind-phone and real status contracts
Add bind_phone captcha scene across schema/runtime/UI, require captcha on phone bind, return real captcha status objects instead of legacy option aliases, and harden form discovery for page-sign auth forms.
This commit is contained in:
1 parent
fa1ab52b8b
commit
7a4419d0dd
11 files changed
+210
-38
No files matched your search
@@ -148,13 +148,6 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
|
||||
$flat["{$key}_provider"] = (string) ($svc['provider'] ?? '');
|
||||
}
|
||||
|
||||
// 保留旧布尔字段兼容
|
||||
$flat['sms_enabled'] = !empty($services['sms']['enabled']);
|
||||
$flat['wechat_enabled'] = !empty($services['wechat']['enabled']);
|
||||
$flat['captcha_enabled'] = !empty($services['captcha']['enabled']);
|
||||
$flat['baidu_push_enabled'] = !empty($services['push']['enabled']);
|
||||
$flat['content_audit_enabled'] = !empty($services['audit']['enabled']);
|
||||
|
||||
return $this->success([
|
||||
'data' => $flat,
|
||||
'services' => $services,
|
||||
@@ -173,12 +166,11 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
|
||||
$email_gate_enabled = false;
|
||||
}
|
||||
|
||||
$captcha_summary = function_exists('aksrt_get_captcha_status_summary')
|
||||
$captcha = function_exists('aksrt_get_captcha_status_summary')
|
||||
? aksrt_get_captcha_status_summary()
|
||||
: ['enabled' => false, 'configured' => false, 'scenes' => []];
|
||||
$captcha_comment_enabled = !empty($captcha_summary['scenes']['comment']);
|
||||
: ['enabled' => false, 'provider' => '', 'configured' => false, 'scenes' => []];
|
||||
$features = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_cms_features() : [];
|
||||
$captcha_download_enabled = !empty($features['download_captcha']) && !empty($captcha_summary['scenes']['download']);
|
||||
$scenes = is_array($captcha['scenes'] ?? null) ? $captcha['scenes'] : [];
|
||||
|
||||
$risk_switches = [
|
||||
'show_unapproved_comments' => !empty($settings['show_unapproved_comments']),
|
||||
@@ -188,17 +180,25 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
|
||||
|
||||
return $this->success([
|
||||
'data' => [
|
||||
'email_gate_enabled' => $email_gate_enabled,
|
||||
'captcha_comment_enabled' => $captcha_comment_enabled,
|
||||
'captcha_download_enabled' => $captcha_download_enabled,
|
||||
'content_audit_enabled' => !empty($services['audit']['enabled']),
|
||||
'content_audit_configured' => !empty($services['audit']['configured']),
|
||||
'ip_geo_enabled' => !empty($services['ip_geo']['enabled']),
|
||||
'ip_geo_configured' => !empty($services['ip_geo']['configured']),
|
||||
'captcha_enabled' => !empty($captcha_summary['enabled']) && !empty($captcha_summary['configured']),
|
||||
'captcha_summary' => $captcha_summary,
|
||||
'risk_switches' => $risk_switches,
|
||||
'services' => $services,
|
||||
'email_gate_enabled' => $email_gate_enabled,
|
||||
'captcha' => [
|
||||
'enabled' => !empty($captcha['enabled']),
|
||||
'provider' => (string) ($captcha['provider'] ?? ''),
|
||||
'configured' => !empty($captcha['configured']),
|
||||
'scenes' => $scenes,
|
||||
'download_required' => !empty($features['download_captcha']),
|
||||
'download_active' => !empty($features['download_captcha']) && !empty($scenes['download']),
|
||||
],
|
||||
'content_audit' => [
|
||||
'enabled' => !empty($services['audit']['enabled']),
|
||||
'configured' => !empty($services['audit']['configured']),
|
||||
],
|
||||
'ip_geo' => [
|
||||
'enabled' => !empty($services['ip_geo']['enabled']),
|
||||
'configured' => !empty($services['ip_geo']['configured']),
|
||||
],
|
||||
'risk_switches' => $risk_switches,
|
||||
'services' => $services,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class AKSRT_Admin_Schema_Permissions {
|
||||
['label' => '用户登录', 'value' => 'login'],
|
||||
['label' => '用户注册', 'value' => 'register'],
|
||||
['label' => '绑定第三方', 'value' => 'bind'],
|
||||
['label' => '绑定手机', 'value' => 'bind_phone'],
|
||||
['label' => '找回密码', 'value' => 'lostpassword'],
|
||||
['label' => '修改密码', 'value' => 'change_password'],
|
||||
['label' => '更改邮箱', 'value' => 'change_email'],
|
||||
|
||||
@@ -425,6 +425,13 @@ trait AKSRT_Auth_Service_Part_1b {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'aksrt')];
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_require_captcha')) {
|
||||
$captcha_result = aksrt_require_captcha('bind_phone', $post);
|
||||
if ($captcha_result !== true) {
|
||||
return ['success' => false, 'error' => $captcha_result];
|
||||
}
|
||||
}
|
||||
|
||||
// 验证 SMS 验证码
|
||||
if (class_exists('AKSRT_SMS')) {
|
||||
$verify_result = AKSRT_SMS::get_instance()->verify_code($phone, $code);
|
||||
|
||||
@@ -32,6 +32,7 @@ function aksrt_captcha_scenes(): array {
|
||||
'login' => __('用户登录', 'aksrt'),
|
||||
'register' => __('用户注册', 'aksrt'),
|
||||
'bind' => __('绑定第三方', 'aksrt'),
|
||||
'bind_phone' => __('绑定手机', 'aksrt'),
|
||||
'lostpassword' => __('找回密码', 'aksrt'),
|
||||
'change_password' => __('修改密码', 'aksrt'),
|
||||
'change_email' => __('更改邮箱', 'aksrt'),
|
||||
@@ -621,7 +622,22 @@ var triggerCaptcha=function(){ showTip('验证码加载中,请稍候', '#e67e2
|
||||
function findForm(){
|
||||
form=box.closest('form');
|
||||
if(!form&&C.scene==='comment') form=document.getElementById('commentform');
|
||||
if(!form&&C.scene==='login') form=document.getElementById('aksrt-login-form')||document.querySelector('.auth-form');
|
||||
if(!form&&(C.scene==='login'||C.scene==='register')){
|
||||
form=document.getElementById('aksrt-login-form')
|
||||
||document.getElementById('aksrt-modal-login-form')
|
||||
||document.getElementById('sign-login-form')
|
||||
||document.getElementById('aksrt-phone-login-form')
|
||||
||document.getElementById('aksrt-modal-register-form')
|
||||
||document.getElementById('sign-register-form')
|
||||
||document.getElementById('aksrt-phone-register-form')
|
||||
||document.querySelector('.auth-form')
|
||||
||document.querySelector('.sign-form');
|
||||
}
|
||||
if(!form&&C.scene==='bind_phone'){
|
||||
form=document.getElementById('aksrt-bind-phone-form')
|
||||
||document.querySelector('[data-aksrt-bind-phone-form]')
|
||||
||document.querySelector('.auth-form');
|
||||
}
|
||||
return form;
|
||||
}
|
||||
|
||||
|
||||
@@ -266,6 +266,17 @@ trait AKSRT_Scripts_Part_1b {
|
||||
$version,
|
||||
true
|
||||
);
|
||||
// 绑定手机短信发送按钮依赖 sign-register 的 data-aksrt-sms-trigger 契约
|
||||
$sign_register_js = get_template_directory() . '/assets/js/sign-register.js';
|
||||
if (file_exists($sign_register_js)) {
|
||||
wp_enqueue_script(
|
||||
'aksrt-sign-register',
|
||||
$base_uri . '/assets/js/sign-register.js',
|
||||
['aksrt-route-user-center'],
|
||||
(string) filemtime($sign_register_js),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user