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