Skip to content

Commit

Permalink
fix #579: use allauth messages for header
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Feb 27, 2018
1 parent 6e3e1ef commit d371e78
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
14 changes: 11 additions & 3 deletions codesy/base/middleware.py
@@ -1,4 +1,4 @@
AUTH_CHANGING_PATHS = ['/accounts/logout/', '/accounts/github/login/callback/']
from django.contrib import messages


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

def process_response(self, request, response):
if request.path in AUTH_CHANGING_PATHS:
response['x-codesy-auth-changed'] = 'true'
for message in messages.get_messages(request):
if (
response.status_code == 200 and
(
"Successfully signed in" in message.message or
"You have signed out" in message.message
)
):
response['x-codesy-auth-changed'] = 'true'

return response
3 changes: 2 additions & 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 Expand Up @@ -107,6 +107,7 @@
# OAuth2View uses this for the callback_url protocol
ACCOUNT_DEFAULT_HTTP_PROTOCOL = config(
'ACCOUNT_DEFAULT_HTTP_PROTOCOL', default='http')
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_ADAPTER = 'codesy.adapters.CodesySocialAccountAdapter'
SOCIALACCOUNT_QUERY_EMAIL = True
Expand Down
2 changes: 1 addition & 1 deletion codesy/templates/base.html
Expand Up @@ -35,7 +35,7 @@
<li><a href="{% url 'card' %}">Credit Card</a></li>
<li><a href="{% url 'bank' %}">Bank Account</a></li>
<hr/>
<li><a href="{% url 'account_logout' %}">Sign out</a></li>
<li><form action="{% url 'account_logout' %}" method="post">{% csrf_token %}<input type="submit" class="button top-bar-dropdown-signout" value="Sign out"></form></li>
</ul>
</li>
{% endif %}
Expand Down
2 changes: 0 additions & 2 deletions codesy/urls.py
@@ -1,6 +1,5 @@
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.views import LogoutView

from . import views

Expand All @@ -12,7 +11,6 @@
url(r'^$', views.Home.as_view(), name='home'),
url(r'^legal-info$', views.LegalInfo.as_view(), name='legal-info'),
# allauth
url(r'^accounts/logout/$', LogoutView.as_view(), {'next_page': '/'}),
url(r'^accounts/', include('allauth.urls')),

# admin site
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -2,7 +2,7 @@ Django==1.11.5
PyGithub==1.26.0
dj-database-url==0.4.0
dj-static==0.0.6
django-allauth==0.24.1
django-allauth==0.32.0
django-csp==3.1
django-cors-headers==1.1.0
django-mailer==1.2.2
Expand Down
4 changes: 4 additions & 0 deletions static/css/codesy-home.css
Expand Up @@ -82,6 +82,10 @@ tr.total {
background-color: #F5F5F5;
}

.top-bar-dropdown-signout {
margin: 0 1rem 1rem;
}

img {
border-width:0;
}
Expand Down

0 comments on commit d371e78

Please sign in to comment.