diff --git a/apps/authentication/api/login_confirm.py b/apps/authentication/api/login_confirm.py index 57c6dff3f..aa0e43ead 100644 --- a/apps/authentication/api/login_confirm.py +++ b/apps/authentication/api/login_confirm.py @@ -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() diff --git a/apps/authentication/api/mfa.py b/apps/authentication/api/mfa.py index a0bec8216..d55a238d2 100644 --- a/apps/authentication/api/mfa.py +++ b/apps/authentication/api/mfa.py @@ -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) diff --git a/apps/authentication/api/token.py b/apps/authentication/api/token.py index 7242cf9b5..980ff4c11 100644 --- a/apps/authentication/api/token.py +++ b/apps/authentication/api/token.py @@ -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) diff --git a/apps/authentication/errors.py b/apps/authentication/errors.py index 5e7506e90..18fb09e73 100644 --- a/apps/authentication/errors.py +++ b/apps/authentication/errors.py @@ -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): diff --git a/apps/authentication/templates/authentication/login_wait_confirm.html b/apps/authentication/templates/authentication/login_wait_confirm.html index e653fb072..3be63bd1f 100644 --- a/apps/authentication/templates/authentication/login_wait_confirm.html +++ b/apps/authentication/templates/authentication/login_wait_confirm.html @@ -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 })