From 7cd1e4d3a01d40a07d727f50ef0ea7146594cab2 Mon Sep 17 00:00:00 2001 From: "Gerry.tan" Date: Thu, 25 Sep 2025 15:12:45 +0800 Subject: [PATCH] perf: Dynamically configure the validity period of the email verification code --- apps/authentication/api/password.py | 3 ++- apps/authentication/mfa/email.py | 5 +++-- .../templates/authentication/_msg_mfa_email_code.html | 2 +- .../authentication/_msg_reset_password_code.html | 2 +- apps/i18n/core/en/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/es/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/ja/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/ko/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/pt_BR/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/ru/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/zh/LC_MESSAGES/django.po | 10 +++++----- apps/i18n/core/zh_Hant/LC_MESSAGES/django.po | 10 +++++----- 12 files changed, 47 insertions(+), 45 deletions(-) diff --git a/apps/authentication/api/password.py b/apps/authentication/api/password.py index 3453a6d8b..3df6d0ea1 100644 --- a/apps/authentication/api/password.py +++ b/apps/authentication/api/password.py @@ -67,8 +67,9 @@ class UserResetPasswordSendCodeApi(CreateAPIView): code = random_string(settings.SMS_CODE_LENGTH, lower=False, upper=False) subject = '%s: %s' % (get_login_title(), _('Forgot password')) + tip = _('The validity period of the verification code is {} minute').format(settings.VERIFY_CODE_TTL // 60) context = { - 'user': user, 'title': subject, 'code': code, + 'user': user, 'title': subject, 'code': code, 'tip': tip, } message = render_to_string('authentication/_msg_reset_password_code.html', context) content = {'subject': subject, 'message': message} diff --git a/apps/authentication/mfa/email.py b/apps/authentication/mfa/email.py index dcd834267..ef96981a6 100644 --- a/apps/authentication/mfa/email.py +++ b/apps/authentication/mfa/email.py @@ -39,13 +39,14 @@ class MFAEmail(BaseMFA): def send_challenge(self): code = random_string(settings.SMS_CODE_LENGTH, lower=False, upper=False) subject = '%s: %s' % (get_login_title(), _('MFA code')) + tip = _('The validity period of the verification code is {} minute').format(settings.VERIFY_CODE_TTL // 60) context = { - 'user': self.user, 'title': subject, 'code': code, + 'user': self.user, 'title': subject, 'code': code, 'tip': tip, } message = render_to_string('authentication/_msg_mfa_email_code.html', context) content = {'subject': subject, 'message': message} sender_util = SendAndVerifyCodeUtil( - self.user.email, code=code, backend=self.name, timeout=60, **content + self.user.email, code=code, backend=self.name, **content ) sender_util.gen_and_send_async() diff --git a/apps/authentication/templates/authentication/_msg_mfa_email_code.html b/apps/authentication/templates/authentication/_msg_mfa_email_code.html index 18abd728d..cc0ec3274 100644 --- a/apps/authentication/templates/authentication/_msg_mfa_email_code.html +++ b/apps/authentication/templates/authentication/_msg_mfa_email_code.html @@ -12,7 +12,7 @@ {% trans 'MFA code' %}: {{ code }} - {% trans 'The validity period of the verification code is one minute' %} + {{ tip }} diff --git a/apps/authentication/templates/authentication/_msg_reset_password_code.html b/apps/authentication/templates/authentication/_msg_reset_password_code.html index fc8d7a64e..eb751a24f 100644 --- a/apps/authentication/templates/authentication/_msg_reset_password_code.html +++ b/apps/authentication/templates/authentication/_msg_reset_password_code.html @@ -15,7 +15,7 @@ {% trans 'Copy the verification code to the Reset Password page to reset the password.' %} - {% trans 'The validity period of the verification code is one minute' %} + {{ tip }} diff --git a/apps/i18n/core/en/LC_MESSAGES/django.po b/apps/i18n/core/en/LC_MESSAGES/django.po index 4457e8e75..64e1d56ba 100644 --- a/apps/i18n/core/en/LC_MESSAGES/django.po +++ b/apps/i18n/core/en/LC_MESSAGES/django.po @@ -3759,6 +3759,11 @@ msgstr "" msgid "Forgot password" msgstr "" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "" + #: authentication/apps.py:7 msgid "App Authentication" msgstr "Authentication" @@ -4490,11 +4495,6 @@ msgid "" "account password in time." msgstr "" -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "" - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "" diff --git a/apps/i18n/core/es/LC_MESSAGES/django.po b/apps/i18n/core/es/LC_MESSAGES/django.po index 8da2d0de2..54cae62cc 100644 --- a/apps/i18n/core/es/LC_MESSAGES/django.po +++ b/apps/i18n/core/es/LC_MESSAGES/django.po @@ -3977,6 +3977,11 @@ msgstr "" msgid "Forgot password" msgstr "Olvidé la contraseña" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "El código de verificación tiene una validez de {} minuto." + #: authentication/apps.py:7 msgid "App Authentication" msgstr "Gestión de autenticación" @@ -4758,11 +4763,6 @@ msgstr "" "Si sospechas que este acceso es irregular, te recomendamos que cambies la " "contraseña de tu cuenta lo antes posible." -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "El código de verificación tiene una validez de 1 minuto." - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "Tu cuenta ha sido vinculada recientemente a" diff --git a/apps/i18n/core/ja/LC_MESSAGES/django.po b/apps/i18n/core/ja/LC_MESSAGES/django.po index 205d6de47..47bb1959e 100644 --- a/apps/i18n/core/ja/LC_MESSAGES/django.po +++ b/apps/i18n/core/ja/LC_MESSAGES/django.po @@ -3803,6 +3803,11 @@ msgstr "ユーザーは {}からです。対応するシステムにアクセス msgid "Forgot password" msgstr "パスワードを忘れた" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "認証コードの有効時間は {} 分" + #: authentication/apps.py:7 msgid "App Authentication" msgstr "認証" @@ -4537,11 +4542,6 @@ msgid "" "account password in time." msgstr "ログイン動作が異常であると疑われる場合は、時間内にアカウントのパスワードを変更してください。" -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "認証コードの有効時間は 1 分" - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "アカウントはにバインドされています" diff --git a/apps/i18n/core/ko/LC_MESSAGES/django.po b/apps/i18n/core/ko/LC_MESSAGES/django.po index cd9d116c8..e45172ab4 100644 --- a/apps/i18n/core/ko/LC_MESSAGES/django.po +++ b/apps/i18n/core/ko/LC_MESSAGES/django.po @@ -3793,6 +3793,11 @@ msgstr "사용자가 {}에서 옵니다. 해당 시스템에서 비밀번호를 msgid "Forgot password" msgstr "비밀번호를 잊으셨나요" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "인증 코드의 유효 기간은 {} 분입니다." + #: authentication/apps.py:7 msgid "App Authentication" msgstr "인증 관리" @@ -4537,11 +4542,6 @@ msgid "" "account password in time." msgstr "이번 로그인 행위가 이상하다고 생각되시면, 즉시 계정 비밀번호를 수정하시기 바랍니다." -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "인증 코드의 유효 기간은 1분입니다." - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "귀하의 계정이 방금" diff --git a/apps/i18n/core/pt_BR/LC_MESSAGES/django.po b/apps/i18n/core/pt_BR/LC_MESSAGES/django.po index ec7dc349d..d18c7518c 100644 --- a/apps/i18n/core/pt_BR/LC_MESSAGES/django.po +++ b/apps/i18n/core/pt_BR/LC_MESSAGES/django.po @@ -3928,6 +3928,11 @@ msgstr "" msgid "Forgot password" msgstr "Esqueceu a senha" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "O código de verificação é válido por {} minuto" + #: authentication/apps.py:7 msgid "App Authentication" msgstr "gerenciamento de autenticação" @@ -4695,11 +4700,6 @@ msgstr "" "Se você suspeita de atividades incomuns, por favor, altere sua senha " "imediatamente" -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "O código de verificação é válido por 1 minuto" - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "Sua conta acaba de ser conectada a" diff --git a/apps/i18n/core/ru/LC_MESSAGES/django.po b/apps/i18n/core/ru/LC_MESSAGES/django.po index 8097cbdf0..59ac9e730 100644 --- a/apps/i18n/core/ru/LC_MESSAGES/django.po +++ b/apps/i18n/core/ru/LC_MESSAGES/django.po @@ -3907,6 +3907,11 @@ msgstr "" msgid "Forgot password" msgstr "Забыли пароль" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "Код подтверждения действителен в течение {} минуты" + #: authentication/apps.py:7 msgid "App Authentication" msgstr "Управление аутентификацией" @@ -4676,11 +4681,6 @@ msgstr "" "Если вы подозреваете, что этот вход был подозрительным, пожалуйста, срочно " "измените пароль." -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "Код подтверждения действителен в течение 1 минуты" - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "Ваша учетная запись только что была привязана к" diff --git a/apps/i18n/core/zh/LC_MESSAGES/django.po b/apps/i18n/core/zh/LC_MESSAGES/django.po index d8e607fd9..c2c3dd19b 100644 --- a/apps/i18n/core/zh/LC_MESSAGES/django.po +++ b/apps/i18n/core/zh/LC_MESSAGES/django.po @@ -3862,6 +3862,11 @@ msgstr "用户来自 {} 请去相应系统修改密码" msgid "Forgot password" msgstr "忘记密码" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "验证码有效期为 {} 分钟" + #: authentication/apps.py:7 msgid "App Authentication" msgstr "认证管理" @@ -4608,11 +4613,6 @@ msgid "" "account password in time." msgstr "若怀疑此次登录行为异常,请及时修改账号密码" -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "验证码有效期为 1 分钟" - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "您的帐户刚刚绑定到" diff --git a/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po b/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po index cb92e880d..0eb99b2fa 100644 --- a/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po +++ b/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po @@ -3781,6 +3781,11 @@ msgstr "用戶來自 {} 請去相應系統修改密碼" msgid "Forgot password" msgstr "忘記密碼" +#: authentication/api/password.py:70 +#: authentication/mfa/email.py:42 +msgid "The validity period of the verification code is {} minute" +msgstr "驗證碼有效期為 {} 分鐘" + #: authentication/apps.py:7 msgid "App Authentication" msgstr "身份验证管理" @@ -4513,11 +4518,6 @@ msgid "" "account password in time." msgstr "若懷疑此次登錄行為異常,請及時修改帳號密碼" -#: authentication/templates/authentication/_msg_mfa_email_code.html:15 -#: authentication/templates/authentication/_msg_reset_password_code.html:18 -msgid "The validity period of the verification code is one minute" -msgstr "驗證碼有效期為 1 分鐘" - #: authentication/templates/authentication/_msg_oauth_bind.html:6 msgid "Your account has just been bound to" msgstr "您的帳戶剛剛綁定到"