From ef7329a721e7e36c09c656596f33eccff768bdde Mon Sep 17 00:00:00 2001 From: jiangweidong <1053570670@qq.com> Date: Fri, 19 Apr 2024 17:11:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=A2=91=E7=B9=81?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9F=AD=E4=BF=A1=EF=BC=8C=E5=B0=86=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E9=A2=91=E7=B9=81=E5=8F=91=E9=80=81=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E6=8F=90=E7=A4=BA=E5=88=B0=E9=A1=B5=E9=9D=A2=E4=B8=8A?= =?UTF-8?q?=E6=9D=A5=E6=8F=90=E9=86=92=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/mfa.py | 4 +++- apps/common/utils/verify_code.py | 8 ++++---- apps/templates/_mfa_login_field.html | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/authentication/api/mfa.py b/apps/authentication/api/mfa.py index 2d3a9b072..ed88b116e 100644 --- a/apps/authentication/api/mfa.py +++ b/apps/authentication/api/mfa.py @@ -9,7 +9,7 @@ from rest_framework.permissions import AllowAny from rest_framework.response import Response from rest_framework.serializers import ValidationError -from common.exceptions import UnexpectError +from common.exceptions import JMSException, UnexpectError from common.utils import get_logger from users.models.user import User from .. import errors @@ -61,6 +61,8 @@ class MFASendCodeApi(AuthMixin, CreateAPIView): try: mfa_backend.send_challenge() + except JMSException: + raise except Exception as e: raise UnexpectError(str(e)) diff --git a/apps/common/utils/verify_code.py b/apps/common/utils/verify_code.py index 7b2589f7d..115752f82 100644 --- a/apps/common/utils/verify_code.py +++ b/apps/common/utils/verify_code.py @@ -30,14 +30,14 @@ class SendAndVerifyCodeUtil(object): self.other_args = kwargs def gen_and_send_async(self): - return send_async.apply_async(kwargs={"sender": self}, priority=100) - - def gen_and_send(self): ttl = self.__ttl() if ttl > 0: - logger.error('Send sms too frequently, delay {}'.format(ttl)) + logger.warning('Send sms too frequently, delay {}'.format(ttl)) raise CodeSendTooFrequently(ttl) + return send_async.apply_async(kwargs={"sender": self}, priority=100) + + def gen_and_send(self): try: if not self.code: self.code = self.__generate() diff --git a/apps/templates/_mfa_login_field.html b/apps/templates/_mfa_login_field.html index 412b369ca..ec2477d1f 100644 --- a/apps/templates/_mfa_login_field.html +++ b/apps/templates/_mfa_login_field.html @@ -118,11 +118,18 @@ }) } + function onError (responseText, responseJson, status) { + setTimeout(function () { + toastr.error(responseJson.detail); + }); + }; + requestApi({ url: url, method: "POST", body: JSON.stringify(data), success: onSuccess, + error: onError, flash_message: false }) }