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