0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

chore(phrases,core): change 'passcode' to 'verification code' in content (#2740)

This commit is contained in:
Darcy Ye 2022-12-28 10:29:28 +08:00 committed by GitHub
parent a3a861c9cd
commit 1f7efd3680
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 79 additions and 75 deletions

View file

@ -113,7 +113,7 @@ describe('sendPasscode', () => {
createdAt: Date.now(), createdAt: Date.now(),
}; };
await expect(sendPasscode(passcode)).rejects.toThrowError( await expect(sendPasscode(passcode)).rejects.toThrowError(
new RequestError('passcode.phone_email_empty') new RequestError('verification_code.phone_email_empty')
); );
}); });
@ -230,7 +230,7 @@ describe('verifyPasscode', () => {
findUnconsumedPasscodeByJtiAndType.mockResolvedValue(null); findUnconsumedPasscodeByJtiAndType.mockResolvedValue(null);
await expect( await expect(
verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' }) verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' })
).rejects.toThrow(new RequestError('passcode.not_found')); ).rejects.toThrow(new RequestError('verification_code.not_found'));
}); });
it('should fail when phone mismatch', async () => { it('should fail when phone mismatch', async () => {
@ -239,7 +239,7 @@ describe('verifyPasscode', () => {
verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, {
phone: 'invalid_phone', phone: 'invalid_phone',
}) })
).rejects.toThrow(new RequestError('passcode.phone_mismatch')); ).rejects.toThrow(new RequestError('verification_code.phone_mismatch'));
}); });
it('should fail when email mismatch', async () => { it('should fail when email mismatch', async () => {
@ -252,7 +252,7 @@ describe('verifyPasscode', () => {
verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, {
email: 'invalid_email', email: 'invalid_email',
}) })
).rejects.toThrow(new RequestError('passcode.email_mismatch')); ).rejects.toThrow(new RequestError('verification_code.email_mismatch'));
}); });
it('should fail when expired', async () => { it('should fail when expired', async () => {
@ -262,7 +262,7 @@ describe('verifyPasscode', () => {
}); });
await expect( await expect(
verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' }) verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' })
).rejects.toThrow(new RequestError('passcode.expired')); ).rejects.toThrow(new RequestError('verification_code.expired'));
}); });
it('should fail when exceed max count', async () => { it('should fail when exceed max count', async () => {
@ -272,14 +272,14 @@ describe('verifyPasscode', () => {
}); });
await expect( await expect(
verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' }) verifyPasscode(passcode.interactionJti, passcode.type, passcode.code, { phone: 'phone' })
).rejects.toThrow(new RequestError('passcode.exceed_max_try')); ).rejects.toThrow(new RequestError('verification_code.exceed_max_try'));
}); });
it('should fail when invalid code, and should increase try_count', async () => { it('should fail when invalid code, and should increase try_count', async () => {
findUnconsumedPasscodeByJtiAndType.mockResolvedValue(passcode); findUnconsumedPasscodeByJtiAndType.mockResolvedValue(passcode);
await expect( await expect(
verifyPasscode(passcode.interactionJti, passcode.type, 'invalid', { phone: 'phone' }) verifyPasscode(passcode.interactionJti, passcode.type, 'invalid', { phone: 'phone' })
).rejects.toThrow(new RequestError('passcode.code_mismatch')); ).rejects.toThrow(new RequestError('verification_code.code_mismatch'));
expect(increasePasscodeTryCount).toHaveBeenCalledWith(passcode.id); expect(increasePasscodeTryCount).toHaveBeenCalledWith(passcode.id);
}); });
}); });

View file

@ -45,7 +45,7 @@ export const sendPasscode = async (passcode: Passcode) => {
const emailOrPhone = passcode.email ?? passcode.phone; const emailOrPhone = passcode.email ?? passcode.phone;
if (!emailOrPhone) { if (!emailOrPhone) {
throw new RequestError('passcode.phone_email_empty'); throw new RequestError('verification_code.phone_email_empty');
} }
const expectType = passcode.phone ? ConnectorType.Sms : ConnectorType.Email; const expectType = passcode.phone ? ConnectorType.Sms : ConnectorType.Email;
@ -95,28 +95,28 @@ export const verifyPasscode = async (
const passcode = await findUnconsumedPasscodeByJtiAndType(sessionId, type); const passcode = await findUnconsumedPasscodeByJtiAndType(sessionId, type);
if (!passcode) { if (!passcode) {
throw new RequestError('passcode.not_found'); throw new RequestError('verification_code.not_found');
} }
if ('phone' in payload && passcode.phone !== payload.phone) { if ('phone' in payload && passcode.phone !== payload.phone) {
throw new RequestError('passcode.phone_mismatch'); throw new RequestError('verification_code.phone_mismatch');
} }
if ('email' in payload && passcode.email !== payload.email) { if ('email' in payload && passcode.email !== payload.email) {
throw new RequestError('passcode.email_mismatch'); throw new RequestError('verification_code.email_mismatch');
} }
if (passcode.createdAt + passcodeExpiration < Date.now()) { if (passcode.createdAt + passcodeExpiration < Date.now()) {
throw new RequestError('passcode.expired'); throw new RequestError('verification_code.expired');
} }
if (passcode.tryCount >= passcodeMaxTryCount) { if (passcode.tryCount >= passcodeMaxTryCount) {
throw new RequestError('passcode.exceed_max_try'); throw new RequestError('verification_code.exceed_max_try');
} }
if (code !== passcode.code) { if (code !== passcode.code) {
await increasePasscodeTryCount(passcode.id); await increasePasscodeTryCount(passcode.id);
throw new RequestError('passcode.code_mismatch'); throw new RequestError('verification_code.code_mismatch');
} }
await consumePasscode(passcode.id); await consumePasscode(passcode.id);

View file

@ -48,7 +48,7 @@ jest.mock('#src/libraries/passcode.js', () => ({
sendPasscode: async () => sendPasscode(), sendPasscode: async () => sendPasscode(),
verifyPasscode: async (_a: unknown, _b: unknown, code: string) => { verifyPasscode: async (_a: unknown, _b: unknown, code: string) => {
if (code !== '1234') { if (code !== '1234') {
throw new RequestError('passcode.code_mismatch'); throw new RequestError('verification_code.code_mismatch');
} }
}, },
})); }));

View file

@ -65,7 +65,7 @@ jest.mock('#src/libraries/passcode.js', () => ({
sendPasscode: async () => sendPasscode(), sendPasscode: async () => sendPasscode(),
verifyPasscode: async (_a: unknown, _b: unknown, code: string) => { verifyPasscode: async (_a: unknown, _b: unknown, code: string) => {
if (code !== '1234') { if (code !== '1234') {
throw new RequestError('passcode.code_mismatch'); throw new RequestError('verification_code.code_mismatch');
} }
}, },
})); }));

View file

@ -125,15 +125,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
"This connector's 'metadata' cannot be overwritten.", "This connector's 'metadata' cannot be overwritten.",
}, },
passcode: { verification_code: {
phone_email_empty: 'Telefonnummer oder E-Mail darf nicht leer sein.', phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED
not_found: 'Passcode nicht gefunden. Bitte sende erst einen Passcode.', not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED
phone_mismatch: phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED
'Telefonnummer stimmt nicht mit Passcode überein. Frage einen neuen Passcode an.', email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED
email_mismatch: 'E-Mail stimmt nicht mit Passcode überein. Frage einen neuen Passcode an.', code_mismatch: 'Invalid verification code.', // UNTRANSLATED
code_mismatch: 'Ungültiger Passcode.', expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED
expired: 'Passcode ist abgelaufen. Frage einen neuen Passcode an.', exceed_max_try:
exceed_max_try: 'Passcode wurde zu oft versucht. Frage einen neuen Passcode an.', 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -124,14 +124,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
"This connector's 'metadata' cannot be overwritten.", "This connector's 'metadata' cannot be overwritten.",
}, },
passcode: { verification_code: {
phone_email_empty: 'Both phone and email are empty.', phone_email_empty: 'Both phone and email are empty.',
not_found: 'Passcode not found. Please send passcode first.', not_found: 'Verification code not found. Please send verification code first.',
phone_mismatch: 'Phone mismatch. Please request a new passcode.', phone_mismatch: 'Phone mismatch. Please request a new verification code.',
email_mismatch: 'Email mismatch. Please request a new passcode.', email_mismatch: 'Email mismatch. Please request a new verification code.',
code_mismatch: 'Invalid passcode.', code_mismatch: 'Invalid verification code.',
expired: 'Passcode has expired. Please request a new passcode.', expired: 'Verification code has expired. Please request a new verification code.',
exceed_max_try: 'Passcode verification limitation exceeded. Please request a new passcode.', exceed_max_try:
'Verification code retries limitation exceeded. Please request a new verification code.',
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -131,15 +131,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
"This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED
}, },
passcode: { verification_code: {
phone_email_empty: "Le téléphone et l'email sont vides.", phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED
not_found: "Le code d'accès n'a pas été trouvé. Veuillez envoyer le code d'accès en premier.", not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED
phone_mismatch: "Le téléphone ne correspond pas. Veuillez demander un nouveau code d'accès.", phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED
email_mismatch: "Erreur d'email. Veuillez demander un nouveau code d'accès.", email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED
code_mismatch: "Code d'accès invalide.", code_mismatch: 'Invalid verification code.', // UNTRANSLATED
expired: "Le code d'accès a expiré. Veuillez demander un nouveau code d'accès.", expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED
exceed_max_try: exceed_max_try:
"La limite de vérification du code d'accès est dépassée. Veuillez demander un nouveau code d'accès.", 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -118,14 +118,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
'이 연동의 메타데이터를 덮어쓸 수 없어요.', '이 연동의 메타데이터를 덮어쓸 수 없어요.',
}, },
passcode: { verification_code: {
phone_email_empty: '휴대전화번호 그리고 이메일이 비어있어요.', phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED
not_found: '비밀번호를 찾을 수 없어요. 비밀번호를 먼저 보내주세요.', not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED
phone_mismatch: '휴대전화번호가 일치하지 않아요. 새로운 비밀번호를 요청해주세요.', phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED
email_mismatch: '이메일이 일치하지 않아요. 새로운 비밀번호를 요청해주세요.', email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED
code_mismatch: '비밀번호가 유효하지 않아요.', code_mismatch: 'Invalid verification code.', // UNTRANSLATED
expired: '비밀번호가 만료되었어요. 새로운 비밀번호를 요청해주세요.', expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED
exceed_max_try: '해당 비밀번호는 인증 횟수를 초과하였어요. 새로운 비밀번호를 요청해주세요.', exceed_max_try:
'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -128,14 +128,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
"This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED
}, },
passcode: { verification_code: {
phone_email_empty: 'Telefone e e-mail estão vazios.', phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED
not_found: 'Senha não encontrada. Por favor, envie a senha primeiro.', not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED
phone_mismatch: 'Incompatibilidade de telefone. Solicite uma nova senha.', phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED
email_mismatch: 'Incompatibilidade de e-mail. Solicite uma nova senha.', email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED
code_mismatch: 'Senha inválida.', code_mismatch: 'Invalid verification code.', // UNTRANSLATED
expired: 'A senha expirou. Solicite uma nova senha.', expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED
exceed_max_try: 'Limite de verificação de senha excedida. Solicite uma nova senha.', exceed_max_try:
'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -126,15 +126,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
"This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED
}, },
passcode: { verification_code: {
phone_email_empty: 'O campos telefone e email estão vazios.', phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED
not_found: 'Senha não encontrada. Por favor, envie a senha primeiro.', not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED
phone_mismatch: 'O telefone não correspond. Por favor, solicite uma nova senha.', phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED
email_mismatch: 'O email não corresponde. Por favor, solicite uma nova senha.', email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED
code_mismatch: 'Senha inválida.', code_mismatch: 'Invalid verification code.', // UNTRANSLATED
expired: 'A senha expirou. Por favor, solicite uma nova senha.', expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED
exceed_max_try: exceed_max_try:
'Limitação de verificação de senha excedida. Por favor, solicite uma nova senha.', 'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -125,14 +125,15 @@ const errors = {
cannot_overwrite_metadata_for_non_standard_connector: cannot_overwrite_metadata_for_non_standard_connector:
"This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED "This connector's 'metadata' cannot be overwritten.", // UNTRANSLATED
}, },
passcode: { verification_code: {
phone_email_empty: 'Hem telefon hem de e-posta adresi yok.', phone_email_empty: 'Both phone and email are empty.', // UNTRANSLATED
not_found: 'Kod bulunamadı. Lütfen önce kodu gönderiniz.', not_found: 'Verification code not found. Please send verification code first.', // UNTRANSLATED
phone_mismatch: 'Telefon numarası eşleşmedi. Lütfen yeni bir kod isteyiniz.', phone_mismatch: 'Phone mismatch. Please request a new verification code.', // UNTRANSLATED
email_mismatch: 'E-posta adresi eşleşmedi. Lütfen yeni bir kod isteyiniz.', email_mismatch: 'Email mismatch. Please request a new verification code.', // UNTRANSLATED
code_mismatch: 'Geçersiz kod.', code_mismatch: 'Invalid verification code.', // UNTRANSLATED
expired: 'Kodun Süresi doldu. Lütfen yeni bir kod isteyiniz.', expired: 'Verification code has expired. Please request a new verification code.', // UNTRANSLATED
exceed_max_try: 'Kod doğrulama sınırııldı. Lütfen yeni bir kod isteyiniz.', exceed_max_try:
'Verification code retries limitation exceeded. Please request a new verification code.', // UNTRANSLATED
}, },
sign_in_experiences: { sign_in_experiences: {
empty_content_url_of_terms_of_use: empty_content_url_of_terms_of_use:

View file

@ -114,7 +114,7 @@ const errors = {
multiple_target_with_same_platform: '不能同时存在多个有相同 target 和平台类型的社交连接器。', multiple_target_with_same_platform: '不能同时存在多个有相同 target 和平台类型的社交连接器。',
cannot_overwrite_metadata_for_non_standard_connector: '不可覆盖该连接器的 metadata 参数。', cannot_overwrite_metadata_for_non_standard_connector: '不可覆盖该连接器的 metadata 参数。',
}, },
passcode: { verification_code: {
phone_email_empty: '手机号与邮箱地址均为空', phone_email_empty: '手机号与邮箱地址均为空',
not_found: '验证码不存在,请先请求发送验证码', not_found: '验证码不存在,请先请求发送验证码',
phone_mismatch: '手机号码不匹配,请尝试请求新的验证码。', phone_mismatch: '手机号码不匹配,请尝试请求新的验证码。',

View file

@ -8,10 +8,10 @@ const useSharedErrorHandler = () => {
// Have to wrap up in a useMemo hook otherwise the handler updates on every cycle // Have to wrap up in a useMemo hook otherwise the handler updates on every cycle
const sharedErrorHandlers: ErrorHandlers = useMemo( const sharedErrorHandlers: ErrorHandlers = useMemo(
() => ({ () => ({
'passcode.expired': (error) => { 'verification_code.expired': (error) => {
setErrorMessage(error.message); setErrorMessage(error.message);
}, },
'passcode.code_mismatch': (error) => { 'verification_code.code_mismatch': (error) => {
setErrorMessage(error.message); setErrorMessage(error.message);
}, },
}), }),