perf: 优化频繁发送短信,将后端的频繁发送警告提示到页面上来提醒用户

pull/13092/head
jiangweidong 7 months ago committed by Bryan
parent ad0bc82539
commit ef7329a721

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

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

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

Loading…
Cancel
Save