From 713dd9276ca1482ca269bd5f65fede5bcebbd49d Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 30 May 2025 13:22:51 +0800 Subject: [PATCH] feat(vben5): Increase the localization of certification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 账户锁定 - 账户未启用 - 用户名或密码错误 - Token已过期 - 需要二次认证 - 密码已过期 --- .../app-antd/src/locales/langs/en-US/abp.json | 8 +++++ .../app-antd/src/locales/langs/zh-CN/abp.json | 8 +++++ .../@abp/account/src/hooks/useOAuthError.ts | 34 +++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json index d6145c3b6..277f4585d 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json @@ -11,6 +11,14 @@ }, "qrcodeLogin": { "scaned": "Please confirm login on your phone." + }, + "errors": { + "accountLockedByInvalidLoginAttempts": "The user account has been locked out due to invalid login attempts. Please wait a while and try again.", + "accountInactive": "You are not allowed to login! Your account is inactive.", + "invalidUserNameOrPassword": "Invalid username or password!", + "tokenHasExpired": "The token is no longer valid!", + "requiresTwoFactor": "Identity verification is required. Please select a verification method!", + "shouldChangePassword": "Your password has expired. Please change it and login!" } }, "manage": { diff --git a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json index 8edd4ab47..0de0f54f4 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json @@ -11,6 +11,14 @@ }, "qrcodeLogin": { "scaned": "请在手机上确认登录." + }, + "errors": { + "accountLockedByInvalidLoginAttempts": "由于尝试登录无效,用户帐户被锁定.请稍候再试!", + "accountInactive": "您不能登录,您的帐户是无效的!", + "invalidUserNameOrPassword": "用户名或密码错误!", + "tokenHasExpired": "您的请求会话已过期,请重新登录!", + "requiresTwoFactor": "需要验证身份,请选择一种验证方式!", + "shouldChangePassword": "您的密码已失效,请修改密码后登录!" } }, "manage": { diff --git a/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts b/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts index d40ada311..456f76525 100644 --- a/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts +++ b/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts @@ -1,3 +1,5 @@ +import { $t } from '@vben/locales'; + interface OAuthError { error: string; error_description?: string; @@ -6,8 +8,36 @@ interface OAuthError { export function useOAuthError() { function formatError(error: OAuthError) { - // TODO: 解决oauth消息国际化. - return error.error_description; + switch (error.error_description) { + // 用户名或密码无效 + case 'Invalid username or password!': { + return $t('abp.oauth.errors.invalidUserNameOrPassword'); + } + // 需要二次认证 + case 'RequiresTwoFactor': { + return $t('abp.oauth.errors.requiresTwoFactor'); + } + // 需要更改密码 + case 'ShouldChangePasswordOnNextLogin': { + return $t('abp.oauth.errors.shouldChangePassword'); + } + // Token已失效 + case 'The token is no longer valid.': { + return $t('abp.oauth.errors.tokenHasExpired'); + } + // 用户尝试登录次数太多,用户被锁定 + case 'The user account has been locked out due to invalid login attempts. Please wait a while and try again.': { + return $t('abp.oauth.errors.accountLockedByInvalidLoginAttempts'); + } + // 用户未启用 + case 'You are not allowed to login! Your account is inactive.': { + return $t('abp.oauth.errors.accountInactive'); + } + // 其他不常用的错误信息返回原始字符串 + default: { + return error.error_description; + } + } } return {