Skip to content

Commit

Permalink
wip: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Feb 26, 2018
1 parent 6e3e1ef commit cd871cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion codesy/base/middleware.py
@@ -1,3 +1,6 @@
from django.contrib import messages


AUTH_CHANGING_PATHS = ['/accounts/logout/', '/accounts/github/login/callback/']


Expand All @@ -7,6 +10,19 @@ class AuthChangedMiddleware(object):
"""

def process_response(self, request, response):
# Set a message for redirected response to catch
if request.path in AUTH_CHANGING_PATHS:
response['x-codesy-auth-changed'] = 'true'
messages.info(request, "auth-changed")

# Catch the auth-changed message and set corresponding header
if response.status_code == 200:
storage = messages.get_messages(request)
for idx, message in enumerate(storage):
if (
message.level == messages.INFO and
message.message == "auth-changed"
):
response['x-codesy-auth-changed'] = 'true'
del storage._loaded_messages[idx]

return response
2 changes: 1 addition & 1 deletion codesy/settings.py
Expand Up @@ -71,9 +71,9 @@
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'codesy.base.middleware.AuthChangedMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'payments.middleware.IdentityVerificationMiddleware',
'codesy.base.middleware.AuthChangedMiddleware'
)


Expand Down

0 comments on commit cd871cb

Please sign in to comment.