fix(ban): state-aware ban copy and real login failure reasons
- fix(profile): 封号用户的公开主页提示不再沿用「当前账号处于限制状态, 部分互动能力已关闭」——封号=全面限制(无法登录),该描述与语境不符。 提示尾句按治理展示态分级:封号→禁封期间无法登录、账号功能全面停用; 小黑屋→发布、评论等操作已受限制;禁言→暂时无法发表评论。 UserRuntime 不再烘焙通用默认文案,缺省时由 get_profile_notice 按态取 - fix(auth): 登录失败透传真实原因——REST auth_login 此前将 Service::login_user 返回的具体错误硬编码为「账号或密码错误」, 禁封用户登录时 Toast 语境错误;现透传 error 字段, friendly_login_error 识别 user_banned 错误码后直接返回禁封文案 (无法登录 + 解封时间/永久 + 原因) - fix(auth): 禁封闸口覆盖全部登录路径——此前仅密码登录经 enforce_login_ban 拦截,短信验证码、公众号扫码、第三方 OAuth 均 直连 complete_login 可绕过封号限制;现将闸口收敛至 complete_login (返回 WP_Error),各调用方中止登录并透出原因;OAuth 重定向新增 account_banned 错误码,auth.js 与 user-center.js 同步文案映射 - test: 新增登录禁封面契约测试(文案单一来源、Toast 透传、免密闸口、 统一收口、前端映射),全量 362 项通过
This commit is contained in:
1 parent
f9bc0f69c4
commit
11eda33e58
12 files changed
+169
-21
No files matched your search
+4
-1
@@ -467,7 +467,10 @@ final class OAuth {
|
||||
if (!$user instanceof \WP_User) {
|
||||
$this->redirect_error('account_match_failed', $provider, 'login');
|
||||
}
|
||||
OAuthAccountService::complete_login($user, true);
|
||||
$login_error = OAuthAccountService::complete_login($user, true);
|
||||
if (is_wp_error($login_error)) {
|
||||
$this->redirect_error('account_banned', $provider, 'login');
|
||||
}
|
||||
$this->redirect_success('login', $provider, OAuthUrlPolicy::validated_redirect($redirect, home_url('/')));
|
||||
}
|
||||
|
||||
|
||||
@@ -97,10 +97,27 @@ final class OAuthAccountService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function complete_login(\WP_User $user, bool $remember = true): void {
|
||||
/**
|
||||
* 完成登录(设置会话与 Cookie)。
|
||||
*
|
||||
* 禁封用户禁止登录:与密码登录的 Restriction::enforce_login_ban 同语义
|
||||
* (封号=无法登录),覆盖短信验证码、公众号扫码、第三方 OAuth 等
|
||||
* 非密码登录路径。返回 WP_Error 时调用方须中止登录并透出原因。
|
||||
*/
|
||||
public static function complete_login(\WP_User $user, bool $remember = true): ?\WP_Error {
|
||||
if (
|
||||
class_exists('\AKSRT\User\Restriction')
|
||||
&& \AKSRT\User\Restriction::get_instance()->is_banned((int) $user->ID)
|
||||
) {
|
||||
return new \WP_Error(
|
||||
'user_banned',
|
||||
\AKSRT\User\Restriction::get_instance()->login_ban_message((int) $user->ID)
|
||||
);
|
||||
}
|
||||
wp_set_current_user($user->ID);
|
||||
wp_set_auth_cookie($user->ID, $remember);
|
||||
do_action('wp_login', $user->user_login, $user);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function bindings(int $user_id): array {
|
||||
|
||||
@@ -209,7 +209,11 @@ final class OAuthProxyClient {
|
||||
$this->redirect_error('account_match_failed', $provider, $action);
|
||||
}
|
||||
|
||||
OAuthAccountService::complete_login($user, true);
|
||||
$login_error = OAuthAccountService::complete_login($user, true);
|
||||
if (is_wp_error($login_error)) {
|
||||
$this->redirect_error('account_banned', $provider, $action);
|
||||
}
|
||||
|
||||
$this->redirect_success(
|
||||
'login',
|
||||
$provider,
|
||||
|
||||
+11
-2
@@ -67,7 +67,13 @@ final class Service {
|
||||
return sanitize_user($login, true);
|
||||
}
|
||||
|
||||
public static function friendly_login_error(string $raw_message): string {
|
||||
public static function friendly_login_error(string $raw_message, string $error_code = ''): string {
|
||||
// 禁封提示已是完整语义文案(无法登录 + 期限 + 原因),直接透出,
|
||||
// 不得泛化为“用户名或密码错误”。
|
||||
if ('user_banned' === $error_code) {
|
||||
return wp_strip_all_tags($raw_message);
|
||||
}
|
||||
|
||||
$msg_lower = wp_strip_all_tags(strtolower($raw_message));
|
||||
|
||||
if (false !== strpos($msg_lower, 'incorrect password') || false !== strpos($msg_lower, '密码不正确')) {
|
||||
@@ -135,7 +141,10 @@ final class Service {
|
||||
}
|
||||
|
||||
if (is_wp_error($user)) {
|
||||
return ['success' => false, 'error' => self::friendly_login_error($user->get_error_message())];
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => self::friendly_login_error($user->get_error_message(), (string) $user->get_error_code()),
|
||||
];
|
||||
}
|
||||
|
||||
// REST API 上下文中 wp_signon 可能无法正确设置 Cookie
|
||||
|
||||
@@ -442,7 +442,10 @@ final class WeixinGzh {
|
||||
if (!$user instanceof \WP_User) {
|
||||
return $this->error_response(is_wp_error($user) ? $user->get_error_message() : __('微信账号匹配失败', 'aksrt'), 400);
|
||||
}
|
||||
OAuthAccountService::complete_login($user, true);
|
||||
$login_error = OAuthAccountService::complete_login($user, true);
|
||||
if (is_wp_error($login_error)) {
|
||||
return $this->error_response($login_error->get_error_message(), 403);
|
||||
}
|
||||
$redirect = OAuthUrlPolicy::validated_redirect((string) ($payload['redirect_to'] ?? ''), home_url('/'));
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
|
||||
Reference in new issue
Block a user