Merge "The background colour of the success message changed"

This commit is contained in:
Jenkins 2017-03-06 05:01:44 +00:00 committed by Gerrit Code Review
commit 93904437f4
5 changed files with 21 additions and 10 deletions

View File

@ -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

View File

@ -51,9 +51,13 @@
</div>
{% endif %}
{% if request.COOKIES.logout_reason %}
<div class="form-group clearfix error help-block alert alert-danger" id="logout_reason">
<p>{{ request.COOKIES.logout_reason }}</p>
</div>
{% if request.COOKIES.logout_status == "success" %}
<div class="form-group clearfix error help-block alert alert-success" id="logout_reason">
{% else %}
<div class="form-group clearfix error help-block alert alert-danger" id="logout_reason">
{% endif %}
<p>{{ request.COOKIES.logout_reason }}</p>
</div>
{% endif %}
{% if next %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ next }}" />

View File

@ -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

View File

@ -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)

View File

@ -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: