diff --git a/horizon/middleware/base.py b/horizon/middleware/base.py index feb1839b35..efcab23de7 100644 --- a/horizon/middleware/base.py +++ b/horizon/middleware/base.py @@ -46,12 +46,12 @@ class HorizonMiddleware(object): logout_reason = None - def _logout(self, request, login_url=None, message=None): + def _logout(self, request, login_url=None, message=None, status='success'): """Logout a user and display a logout message.""" response = auth_views.logout(request, login_url) if message is not None: self.logout_reason = message - utils.add_logout_reason(request, response, message) + utils.add_logout_reason(request, response, message, status) return response def process_request(self, request): @@ -127,7 +127,8 @@ class HorizonMiddleware(object): redirect_field_name=field_name) if isinstance(exception, exceptions.NotAuthorized): logout_reason = _("Unauthorized. Please try logging in again.") - utils.add_logout_reason(request, response, logout_reason) + utils.add_logout_reason(request, response, logout_reason, + 'error') # delete messages, created in get_data() method # since we are going to redirect user to the login page response.delete_cookie('messages') @@ -171,7 +172,8 @@ class HorizonMiddleware(object): redirect_response['logout'] = True if self.logout_reason is not None: utils.add_logout_reason( - request, redirect_response, self.logout_reason) + request, redirect_response, self.logout_reason, + 'error') else: redirect_response = http.HttpResponse() # Use a set while checking if we want a cookie's attributes diff --git a/horizon/templates/auth/_login_form.html b/horizon/templates/auth/_login_form.html index 8f943bb241..b0618c3024 100644 --- a/horizon/templates/auth/_login_form.html +++ b/horizon/templates/auth/_login_form.html @@ -51,9 +51,13 @@ {% endif %} {% if request.COOKIES.logout_reason %} -
-

{{ request.COOKIES.logout_reason }}

-
+ {% if request.COOKIES.logout_status == "success" %} +
+ {% else %} +
+ {% endif %} +

{{ request.COOKIES.logout_reason }}

+
{% endif %} {% if next %} diff --git a/horizon/utils/functions.py b/horizon/utils/functions.py index e49283fbe4..88472c8308 100644 --- a/horizon/utils/functions.py +++ b/horizon/utils/functions.py @@ -39,7 +39,7 @@ def bytes_to_gigabytes(bytes): return int(math.ceil(float(bytes) / units.Gi)) -def add_logout_reason(request, response, reason): +def add_logout_reason(request, response, reason, status='success'): # Store the translated string in the cookie lang = translation.get_language_from_request(request) with translation.override(lang): @@ -47,9 +47,10 @@ def add_logout_reason(request, response, reason): if six.PY2: reason = reason.encode('utf-8') response.set_cookie('logout_reason', reason, max_age=10) + response.set_cookie('logout_status', status, max_age=10) -def logout_with_message(request, msg, redirect=True): +def logout_with_message(request, msg, redirect=True, status='success'): """Send HttpResponseRedirect to LOGOUT_URL. `msg` is a message displayed on the login page after the logout, to explain @@ -61,7 +62,7 @@ def logout_with_message(request, msg, redirect=True): '%s?next=%s' % (settings.LOGOUT_URL, request.path)) else: response = http.HttpResponseRedirect(settings.LOGOUT_URL) - add_logout_reason(request, response, msg) + add_logout_reason(request, response, msg, status) return response diff --git a/openstack_dashboard/dashboards/settings/password/tests.py b/openstack_dashboard/dashboards/settings/password/tests.py index 900b367f0c..7c04ea04e1 100644 --- a/openstack_dashboard/dashboards/settings/password/tests.py +++ b/openstack_dashboard/dashboards/settings/password/tests.py @@ -67,8 +67,10 @@ class ChangePasswordTests(test.TestCase): self.assertRedirectsNoFollow(res, settings.LOGOUT_URL) self.assertIn('logout_reason', res.cookies) + self.assertIn('logout_status', res.cookies) self.assertEqual(res.cookies['logout_reason'].value, "Password changed. Please log in again to continue.") + self.assertEqual('success', res.cookies['logout_status'].value) scheme, netloc, path, query, fragment = urlsplit(res.url) redirect_response = res.client.get(path, http.QueryDict(query)) self.assertRedirectsNoFollow(redirect_response, settings.LOGIN_URL) diff --git a/openstack_dashboard/views.py b/openstack_dashboard/views.py index e3b981d906..98af118b6e 100644 --- a/openstack_dashboard/views.py +++ b/openstack_dashboard/views.py @@ -50,6 +50,8 @@ def splash(request): response = shortcuts.redirect(horizon.get_user_home(request.user)) if 'logout_reason' in request.COOKIES: response.delete_cookie('logout_reason') + if 'logout_status' in request.COOKIES: + response.delete_cookie('logout_status') # Display Message of the Day message from the message files # located in MESSAGES_PATH if MESSAGES_PATH: