perf: Dynamically configure the validity period of the email verification code

dev
Gerry.tan 2025-09-25 15:12:45 +08:00 committed by 老广
parent 64a9987c3f
commit 7cd1e4d3a0
12 changed files with 47 additions and 45 deletions

View File

@ -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}

View File

@ -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()

View File

@ -12,7 +12,7 @@
<td style="height: 50px;">{% trans 'MFA code' %}: <span style="font-weight: bold;">{{ code }}</span></td>
</tr>
<tr style="border: 1px solid #eee">
<td style="height: 30px;">{% trans 'The validity period of the verification code is one minute' %}</td>
<td style="height: 30px;">{{ tip }}</td>
</tr>
</table>
</div>

View File

@ -15,7 +15,7 @@
<td style="height: 30px;"> {% trans 'Copy the verification code to the Reset Password page to reset the password.' %} </td>
</tr>
<tr style="border: 1px solid #eee">
<td style="height: 30px;">{% trans 'The validity period of the verification code is one minute' %}</td>
<td style="height: 30px;">{{ tip }}</td>
</tr>
</table>
</div>

View File

@ -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 ""

View File

@ -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"

View File

@ -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 "アカウントはにバインドされています"

View File

@ -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 "귀하의 계정이 방금"

View File

@ -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"

View File

@ -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 "Ваша учетная запись только что была привязана к"

View File

@ -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 "您的帐户刚刚绑定到"

View File

@ -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 "您的帳戶剛剛綁定到"