From e70d2d1c9e7f49ae1dd27f5b40845dc29e4de429 Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Thu, 7 Nov 2024 20:41:03 +0800 Subject: [PATCH] chore(auth): optimize error message (#5612) --- .../plugin-auth/src/locale/en-US.json | 3 ++- .../plugin-auth/src/locale/zh-CN.json | 3 ++- .../src/server/__tests__/actions.test.ts | 4 ++-- .../plugin-auth/src/server/basic-auth.ts | 4 ++-- .../plugin-auth/src/server/locale/en-US.ts | 19 ------------------- .../plugin-auth/src/server/locale/fr-FR.ts | 19 ------------------- .../plugin-auth/src/server/locale/index.ts | 12 ------------ .../plugin-auth/src/server/locale/ja-JP.ts | 13 ------------- .../plugin-auth/src/server/locale/pt-BR.ts | 19 ------------------- .../plugin-auth/src/server/locale/zh-CN.ts | 19 ------------------- .../src/locale/en_US.json | 4 ++-- .../src/locale/zh_CN.json | 2 +- .../plugin-error-handler/src/server/server.ts | 2 +- 13 files changed, 12 insertions(+), 111 deletions(-) delete mode 100644 packages/plugins/@nocobase/plugin-auth/src/server/locale/en-US.ts delete mode 100644 packages/plugins/@nocobase/plugin-auth/src/server/locale/fr-FR.ts delete mode 100644 packages/plugins/@nocobase/plugin-auth/src/server/locale/index.ts delete mode 100644 packages/plugins/@nocobase/plugin-auth/src/server/locale/ja-JP.ts delete mode 100644 packages/plugins/@nocobase/plugin-auth/src/server/locale/pt-BR.ts delete mode 100644 packages/plugins/@nocobase/plugin-auth/src/server/locale/zh-CN.ts diff --git a/packages/plugins/@nocobase/plugin-auth/src/locale/en-US.json b/packages/plugins/@nocobase/plugin-auth/src/locale/en-US.json index f6f77a628c..02d59fbea1 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/locale/en-US.json +++ b/packages/plugins/@nocobase/plugin-auth/src/locale/en-US.json @@ -23,5 +23,6 @@ "No authentication methods available.": "No authentication methods available.", "The password is inconsistent, please re-enter": "The password is inconsistent, please re-enter", "Sign-in": "Sign-in", - "Password": "Password" + "Password": "Password", + "The username/email or password is incorrect, please re-enter": "The username/email or password is incorrect, please re-enter" } diff --git a/packages/plugins/@nocobase/plugin-auth/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-auth/src/locale/zh-CN.json index 1e244da8a7..c8760b1bc4 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-auth/src/locale/zh-CN.json @@ -23,5 +23,6 @@ "No authentication methods available.": "没有可用的认证方式。", "The password is inconsistent, please re-enter": "密码不一致,请重新输入", "Sign-in": "登录", - "Password": "密码" + "Password": "密码", + "The username/email or password is incorrect, please re-enter": "用户名/邮箱或密码有误,请重新输入" } diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts b/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts index c5f87ca261..ed023169aa 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts @@ -116,7 +116,7 @@ describe('actions', () => { email: 'no-exists@nocobase.com', }); expect(res.statusCode).toEqual(401); - expect(res.error.text).toBe('The username or email is incorrect, please re-enter'); + expect(res.error.text).toBe('The username/email or password is incorrect, please re-enter'); }); it('should check password when signing in', async () => { @@ -125,7 +125,7 @@ describe('actions', () => { password: 'incorrect', }); expect(res.statusCode).toEqual(401); - expect(res.error.text).toBe('The password is incorrect, please re-enter'); + expect(res.error.text).toBe('The username/email or password is incorrect, please re-enter'); }); it('should sign in with password', async () => { diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/basic-auth.ts b/packages/plugins/@nocobase/plugin-auth/src/server/basic-auth.ts index 13c80bada1..281b823ef2 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/basic-auth.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/basic-auth.ts @@ -39,13 +39,13 @@ export class BasicAuth extends BaseAuth { }); if (!user) { - ctx.throw(401, ctx.t('The username or email is incorrect, please re-enter', { ns: namespace })); + ctx.throw(401, ctx.t('The username/email or password is incorrect, please re-enter', { ns: namespace })); } const field = this.userCollection.getField('password'); const valid = await field.verify(password, user.password); if (!valid) { - ctx.throw(401, ctx.t('The password is incorrect, please re-enter', { ns: namespace })); + ctx.throw(401, ctx.t('The username/email or password is incorrect, please re-enter', { ns: namespace })); } return user; } diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/locale/en-US.ts b/packages/plugins/@nocobase/plugin-auth/src/server/locale/en-US.ts deleted file mode 100644 index a5780ac09c..0000000000 --- a/packages/plugins/@nocobase/plugin-auth/src/server/locale/en-US.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * This file is part of the NocoBase (R) project. - * Copyright (c) 2020-2024 NocoBase Co., Ltd. - * Authors: NocoBase Team. - * - * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. - * For more information, please refer to: https://www.nocobase.com/agreement. - */ - -export default { - 'The email is incorrect, please re-enter': 'The email is incorrect, please re-enter', - 'Please fill in your email address': 'Please fill in your email address', - 'The password is incorrect, please re-enter': 'The password is incorrect, please re-enter', - 'Not a valid cellphone number, please re-enter': 'Not a valid cellphone number, please re-enter', - 'The phone number has been registered, please login directly': - 'The phone number has been registered, please login directly', - 'The phone number is not registered, please register first': - 'The phone number is not registered, please register first', -}; diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/locale/fr-FR.ts b/packages/plugins/@nocobase/plugin-auth/src/server/locale/fr-FR.ts deleted file mode 100644 index 58967f0cff..0000000000 --- a/packages/plugins/@nocobase/plugin-auth/src/server/locale/fr-FR.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * This file is part of the NocoBase (R) project. - * Copyright (c) 2020-2024 NocoBase Co., Ltd. - * Authors: NocoBase Team. - * - * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. - * For more information, please refer to: https://www.nocobase.com/agreement. - */ - -export default { - 'The email is incorrect, please re-enter': 'L\'email est incorrect, veuillez le saisir à nouveau', - 'Please fill in your email address': 'Veuillez remplir votre adresse e-mail', - 'The password is incorrect, please re-enter': 'Le mot de passe est incorrect, veuillez le saisir à nouveau', - 'Not a valid cellphone number, please re-enter': 'Numéro de téléphone portable non valide, veuillez le saisir à nouveau', - 'The phone number has been registered, please login directly': - 'Le numéro de téléphone a été enregistré, veuillez vous connecter directement', - 'The phone number is not registered, please register first': - 'Le numéro de téléphone n\'est pas enregistré, veuillez vous inscrire d\'abord', -}; diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/locale/index.ts b/packages/plugins/@nocobase/plugin-auth/src/server/locale/index.ts deleted file mode 100644 index 29e1be6c80..0000000000 --- a/packages/plugins/@nocobase/plugin-auth/src/server/locale/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * This file is part of the NocoBase (R) project. - * Copyright (c) 2020-2024 NocoBase Co., Ltd. - * Authors: NocoBase Team. - * - * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. - * For more information, please refer to: https://www.nocobase.com/agreement. - */ - -export { default as enUS } from './en-US'; -export { default as zhCN } from './zh-CN'; -export { default as ptBR } from './pt-BR'; diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/locale/ja-JP.ts b/packages/plugins/@nocobase/plugin-auth/src/server/locale/ja-JP.ts deleted file mode 100644 index 63406d55ce..0000000000 --- a/packages/plugins/@nocobase/plugin-auth/src/server/locale/ja-JP.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * This file is part of the NocoBase (R) project. - * Copyright (c) 2020-2024 NocoBase Co., Ltd. - * Authors: NocoBase Team. - * - * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. - * For more information, please refer to: https://www.nocobase.com/agreement. - */ - -export default { - 'Please fill in your email address': 'メールアドレスを入力してください', - 'The password is incorrect, please re-enter': 'パスワードが正しくありません。再度入力してください。', -}; diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/locale/pt-BR.ts b/packages/plugins/@nocobase/plugin-auth/src/server/locale/pt-BR.ts deleted file mode 100644 index 6da802d81d..0000000000 --- a/packages/plugins/@nocobase/plugin-auth/src/server/locale/pt-BR.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * This file is part of the NocoBase (R) project. - * Copyright (c) 2020-2024 NocoBase Co., Ltd. - * Authors: NocoBase Team. - * - * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. - * For more information, please refer to: https://www.nocobase.com/agreement. - */ - -export default { - 'The email is incorrect, please re-enter': 'O e-mail está incorreto, por favor, digite novamente', - 'Please fill in your email address': 'Por favor, preencha o seu endereço de e-mail', - 'The password is incorrect, please re-enter': 'A senha está incorreta, por favor, digite novamente', - 'Not a valid cellphone number, please re-enter': 'Número de celular inválido, por favor, digite novamente', - 'The phone number has been registered, please login directly': - 'O número de celular já está registrado, por favor, faça login diretamente', - 'The phone number is not registered, please register first': - 'O número de celular não está registrado, por favor, registre-se primeiro', -}; diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/locale/zh-CN.ts b/packages/plugins/@nocobase/plugin-auth/src/server/locale/zh-CN.ts deleted file mode 100644 index de99c16e07..0000000000 --- a/packages/plugins/@nocobase/plugin-auth/src/server/locale/zh-CN.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * This file is part of the NocoBase (R) project. - * Copyright (c) 2020-2024 NocoBase Co., Ltd. - * Authors: NocoBase Team. - * - * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. - * For more information, please refer to: https://www.nocobase.com/agreement. - */ - -export default { - 'The username or email is incorrect, please re-enter': '用户名或邮箱有误,请重新输入', - 'The password is incorrect, please re-enter': '密码有误,请重新输入', - 'Not a valid cellphone number, please re-enter': '不是有效的手机号,请重新输入', - 'The phone number has been registered, please login directly': '手机号已注册,请直接登录', - 'The phone number is not registered, please register first': '手机号未注册,请先注册', - 'Please keep and enable at least one authenticator': '请至少保留并启用一个认证器', - 'Please enter your username or email': '请输入用户名或邮箱', - 'Please enter a valid username': '请输入有效的用户名', -}; diff --git a/packages/plugins/@nocobase/plugin-error-handler/src/locale/en_US.json b/packages/plugins/@nocobase/plugin-error-handler/src/locale/en_US.json index 1d03ff8807..3601fa9dd1 100644 --- a/packages/plugins/@nocobase/plugin-error-handler/src/locale/en_US.json +++ b/packages/plugins/@nocobase/plugin-error-handler/src/locale/en_US.json @@ -1,6 +1,6 @@ { - "unique violation": "{{field}} must be unique", - "notNull violation": "notNull violation", + "unique violation": "{{field}} already exists", + "notNull violation": "{{field}} cannot be null", "Validation error": "{{field}} validation error", "notNull Violation": "{{field}} cannot be null" } diff --git a/packages/plugins/@nocobase/plugin-error-handler/src/locale/zh_CN.json b/packages/plugins/@nocobase/plugin-error-handler/src/locale/zh_CN.json index 057a84fbca..7bb4234aca 100644 --- a/packages/plugins/@nocobase/plugin-error-handler/src/locale/zh_CN.json +++ b/packages/plugins/@nocobase/plugin-error-handler/src/locale/zh_CN.json @@ -1,5 +1,5 @@ { - "unique violation": "{{field}} 字段值是唯一的", + "unique violation": "{{field}} 字段值已存在", "notNull violation": "{{field}} 字段不能为空", "Validation error": "{{field}} 字段规则验证失败" } diff --git a/packages/plugins/@nocobase/plugin-error-handler/src/server/server.ts b/packages/plugins/@nocobase/plugin-error-handler/src/server/server.ts index 2c6e38c1ce..af20a45f16 100644 --- a/packages/plugins/@nocobase/plugin-error-handler/src/server/server.ts +++ b/packages/plugins/@nocobase/plugin-error-handler/src/server/server.ts @@ -56,7 +56,7 @@ export class PluginErrorHandlerServer extends Plugin { return { message: t(err.type, { ns: this.i18nNs, - field: t(title, { ns: 'lm-collections' }), + field: t(title, { ns: ['lm-collections', 'client'] }), }), }; }),