mirror of https://github.com/jumpserver/jumpserver
[Update] 修改api
parent
f9e41d71dc
commit
bd323d608e
|
@ -63,8 +63,8 @@ class LoginConfirmTicketStatusApi(APIView):
|
|||
raise errors.LoginConfirmOtherError(
|
||||
ticket_id, ticket.get_status_display()
|
||||
)
|
||||
except errors.AuthFailedError as e:
|
||||
return Response(e.as_data(), status=400)
|
||||
except errors.NeedMoreInfoError as e:
|
||||
return Response(e.as_data(), status=200)
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
ticket = self.get_ticket()
|
||||
|
|
|
@ -35,6 +35,8 @@ class MFAChallengeApi(AuthMixin, CreateAPIView):
|
|||
except errors.AuthFailedError as e:
|
||||
data = {"error": e.error, "msg": e.msg}
|
||||
raise ValidationError(data)
|
||||
except errors.NeedMoreInfoError as e:
|
||||
return Response(e.as_data(), status=200)
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
super().create(request, *args, **kwargs)
|
||||
|
|
|
@ -37,3 +37,5 @@ class TokenCreateApi(AuthMixin, CreateAPIView):
|
|||
return resp
|
||||
except errors.AuthFailedError as e:
|
||||
return Response(e.as_data(), status=400)
|
||||
except errors.NeedMoreInfoError as e:
|
||||
return Response(e.as_data(), status=200)
|
||||
|
|
|
@ -130,7 +130,24 @@ class SessionEmptyError(AuthFailedError):
|
|||
error = 'session_empty'
|
||||
|
||||
|
||||
class MFARequiredError(AuthFailedError):
|
||||
class NeedMoreInfoError(Exception):
|
||||
error = ''
|
||||
msg = ''
|
||||
|
||||
def __init__(self, error='', msg=''):
|
||||
if error:
|
||||
self.error = error
|
||||
if msg:
|
||||
self.msg = ''
|
||||
|
||||
def as_data(self):
|
||||
return {
|
||||
'error': self.error,
|
||||
'msg': self.msg,
|
||||
}
|
||||
|
||||
|
||||
class MFARequiredError(NeedMoreInfoError):
|
||||
msg = mfa_required_msg
|
||||
error = 'mfa_required'
|
||||
|
||||
|
@ -145,15 +162,7 @@ class MFARequiredError(AuthFailedError):
|
|||
}
|
||||
|
||||
|
||||
class LoginConfirmRequiredError(AuthFailedError):
|
||||
msg = login_confirm_required_msg
|
||||
error = 'login_confirm_required'
|
||||
|
||||
|
||||
class LoginConfirmError(AuthFailedError):
|
||||
msg = login_confirm_wait_msg
|
||||
error = 'login_confirm_wait'
|
||||
|
||||
class LoginConfirmBaseError(NeedMoreInfoError):
|
||||
def __init__(self, ticket_id, **kwargs):
|
||||
self.ticket_id = ticket_id
|
||||
super().__init__(**kwargs)
|
||||
|
@ -168,12 +177,12 @@ class LoginConfirmError(AuthFailedError):
|
|||
}
|
||||
|
||||
|
||||
class LoginConfirmWaitError(LoginConfirmError):
|
||||
class LoginConfirmWaitError(LoginConfirmBaseError):
|
||||
msg = login_confirm_wait_msg
|
||||
error = 'login_confirm_wait'
|
||||
|
||||
|
||||
class LoginConfirmOtherError(LoginConfirmError):
|
||||
class LoginConfirmOtherError(LoginConfirmBaseError):
|
||||
error = 'login_confirm_error'
|
||||
|
||||
def __init__(self, ticket_id, status):
|
||||
|
|
|
@ -80,12 +80,7 @@ function doRequestAuth() {
|
|||
requestApi({
|
||||
url: url,
|
||||
method: "GET",
|
||||
success: function () {
|
||||
clearInterval(interval);
|
||||
clearInterval(checkInterval);
|
||||
window.location = successUrl;
|
||||
},
|
||||
error: function (text, data) {
|
||||
success: function (data) {
|
||||
if (data.error !== "login_confirm_wait") {
|
||||
if (!errorMsgShow) {
|
||||
infoMsgRef.hide();
|
||||
|
@ -97,7 +92,13 @@ function doRequestAuth() {
|
|||
clearInterval(checkInterval);
|
||||
$(".copy-btn").attr('disabled', 'disabled')
|
||||
}
|
||||
errorMsgRef.html(data.msg)
|
||||
if (data.msg === 'ok' && !data.error) {
|
||||
window.location = "{% url 'authentication:login-guard' %}"
|
||||
} else {
|
||||
errorMsgRef.html(data.msg)
|
||||
}
|
||||
},
|
||||
error: function (text, data) {
|
||||
},
|
||||
flash_message: false
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue