mirror of https://github.com/jumpserver/jumpserver
perf: 优化频繁发送短信,将后端的频繁发送警告提示到页面上来提醒用户
parent
ad0bc82539
commit
ef7329a721
|
@ -9,7 +9,7 @@ from rest_framework.permissions import AllowAny
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import ValidationError
|
from rest_framework.serializers import ValidationError
|
||||||
|
|
||||||
from common.exceptions import UnexpectError
|
from common.exceptions import JMSException, UnexpectError
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
from users.models.user import User
|
from users.models.user import User
|
||||||
from .. import errors
|
from .. import errors
|
||||||
|
@ -61,6 +61,8 @@ class MFASendCodeApi(AuthMixin, CreateAPIView):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mfa_backend.send_challenge()
|
mfa_backend.send_challenge()
|
||||||
|
except JMSException:
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise UnexpectError(str(e))
|
raise UnexpectError(str(e))
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,14 @@ class SendAndVerifyCodeUtil(object):
|
||||||
self.other_args = kwargs
|
self.other_args = kwargs
|
||||||
|
|
||||||
def gen_and_send_async(self):
|
def gen_and_send_async(self):
|
||||||
|
ttl = self.__ttl()
|
||||||
|
if ttl > 0:
|
||||||
|
logger.warning('Send sms too frequently, delay {}'.format(ttl))
|
||||||
|
raise CodeSendTooFrequently(ttl)
|
||||||
|
|
||||||
return send_async.apply_async(kwargs={"sender": self}, priority=100)
|
return send_async.apply_async(kwargs={"sender": self}, priority=100)
|
||||||
|
|
||||||
def gen_and_send(self):
|
def gen_and_send(self):
|
||||||
ttl = self.__ttl()
|
|
||||||
if ttl > 0:
|
|
||||||
logger.error('Send sms too frequently, delay {}'.format(ttl))
|
|
||||||
raise CodeSendTooFrequently(ttl)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not self.code:
|
if not self.code:
|
||||||
self.code = self.__generate()
|
self.code = self.__generate()
|
||||||
|
|
|
@ -118,11 +118,18 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onError (responseText, responseJson, status) {
|
||||||
|
setTimeout(function () {
|
||||||
|
toastr.error(responseJson.detail);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
requestApi({
|
requestApi({
|
||||||
url: url,
|
url: url,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
success: onSuccess,
|
success: onSuccess,
|
||||||
|
error: onError,
|
||||||
flash_message: false
|
flash_message: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue