From f53cf8d544b391550937821680636c3972afd436 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 11 Nov 2019 16:43:09 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E9=99=86=E5=B7=A5=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/login_confirm.py | 1 + apps/authentication/errors.py | 2 +- apps/authentication/mixins.py | 2 +- .../authentication/login_wait_confirm.html | 40 +++++++++++++++---- apps/authentication/views/login.py | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/apps/authentication/api/login_confirm.py b/apps/authentication/api/login_confirm.py index e64deeef8..5232dd753 100644 --- a/apps/authentication/api/login_confirm.py +++ b/apps/authentication/api/login_confirm.py @@ -54,5 +54,6 @@ class LoginConfirmTicketStatusApi(mixins.AuthMixin, APIView): def delete(self, request, *args, **kwargs): ticket = self.get_ticket() if ticket: + request.session.pop('auth_ticket_id', '') ticket.perform_status('closed', request.user) return Response('', status=200) diff --git a/apps/authentication/errors.py b/apps/authentication/errors.py index 18fb09e73..9df4ad1f7 100644 --- a/apps/authentication/errors.py +++ b/apps/authentication/errors.py @@ -138,7 +138,7 @@ class NeedMoreInfoError(Exception): if error: self.error = error if msg: - self.msg = '' + self.msg = msg def as_data(self): return { diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index be7bfaf7d..ceb54f592 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -115,7 +115,7 @@ class AuthMixin: def get_ticket_or_create(self, confirm_setting): ticket = self.get_ticket() - if not ticket: + if not ticket or ticket.status == ticket.STATUS_CLOSED: ticket = confirm_setting.create_confirm_ticket(self.request) self.request.session['auth_ticket_id'] = str(ticket.id) return ticket diff --git a/apps/authentication/templates/authentication/login_wait_confirm.html b/apps/authentication/templates/authentication/login_wait_confirm.html index 99841438e..28f84baf9 100644 --- a/apps/authentication/templates/authentication/login_wait_confirm.html +++ b/apps/authentication/templates/authentication/login_wait_confirm.html @@ -37,18 +37,18 @@
-
+ -
+ -
- + @@ -82,6 +82,7 @@ function doRequestAuth() { method: "GET", success: function (data) { if (!data.error && data.msg === 'ok') { + window.onbeforeunload = function(){}; window.location = "{% url 'authentication:login-guard' %}" } else if (data.error !== "login_confirm_wait") { if (!errorMsgShow) { @@ -125,17 +126,40 @@ function handleProgressBar() { progressBarRef.attr('aria-valuenow', offset); } +function cancelLoginConfirmTicket() { + requestApi({ + url: url, + method: "DELETE", + flash_message: false + }) +} + +function cancelCloseConfirm() { + window.onbeforeunload = function() {}; + window.onunload = function(){}; +} + +function setCloseConfirm() { + window.onbeforeunload = function (e) { + return 'Confirm'; + }; + window.onunload = function (e) { + cancelLoginConfirmTicket(); + } +} + $(document).ready(function () { interval = setInterval(handleProgressBar, 1000); checkInterval = setInterval(doRequestAuth, 5000); doRequestAuth(); initClipboard(); - window.onbeforeunload = function (e) { - return "{% trans "Confirm" %}"; - }; + setCloseConfirm(); }).on('click', '.btn-refresh', function () { - window.onbeforeunload = function() {}; + cancelCloseConfirm(); window.location.reload(); +}).on('click', '.btn-return', function () { + cancelCloseConfirm(); + window.location = "{% url 'authentication:login' %}" }) diff --git a/apps/authentication/views/login.py b/apps/authentication/views/login.py index 94226a237..873057169 100644 --- a/apps/authentication/views/login.py +++ b/apps/authentication/views/login.py @@ -152,8 +152,8 @@ class UserLoginWaitConfirmView(TemplateView): ticket = get_object_or_none(LoginConfirmTicket, pk=ticket_id) context = super().get_context_data(**kwargs) if ticket: - ticket_detail_url = reverse('tickets:login-confirm-ticket-detail', kwargs={'pk': ticket_id}) timestamp_created = datetime.datetime.timestamp(ticket.date_created) + ticket_detail_url = reverse('tickets:login-confirm-ticket-detail', kwargs={'pk': ticket_id}) msg = _("""Wait for {} confirm, You also can copy link to her/him
Don't close this page""").format(ticket.assignees_display) else: