Skip to content

Commit

Permalink
Fixes part of #26. Authentication with Dreamjub works.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuboschek committed Mar 10, 2017
1 parent cee2f16 commit a3b229b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
10 changes: 8 additions & 2 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ def home(request):
results = Vote.objects.filter(status__stage=Status.PUBLIC)

if request.user.is_authenticated():
details = json.loads(request.user.profile.details)
votes_shown = [v for v in votes if v.filter.matches(details)]
try:
details = request.user.socialaccount_set.get(
provider='dreamjub').extra_data
except request.user.DoesNotExist:
details = {}

votes_shown = [v for v in votes if v.filter.matches(json.loads(
details))]

ctx["vote_list_title"] = "Your votes"

Expand Down
17 changes: 15 additions & 2 deletions jay/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',

'django_forms_bootstrap',

'allauth',
'allauth.account',
'allauth.socialaccount',
'dreamjub.providers.oauth',

'filters',
'settings',
'users',
Expand Down Expand Up @@ -66,8 +74,10 @@
WSGI_APPLICATION = 'jay.wsgi.application'

# OpenJUB auth
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend',
'users.ojub_auth.OjubBackend')
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)

# Default after login redirect
# These are named URL routes
Expand All @@ -93,3 +103,6 @@
)

STATIC_URL = '/static/'
SITE_ID = 1

ACCOUNT_EMAIL_VERIFICATION = "none"
2 changes: 1 addition & 1 deletion jay/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
url(r'^help/filters/$', TemplateView.as_view(template_name="filters/filter_help.html"), name="filter_help"),

# Authentication
url(r'^login/', auth_views.login, {'template_name': 'auth/login.html'}, name="login"),
url(r'^accounts/', include('allauth.urls'), name='login'),
url(r'^logout/', auth_views.logout, {'template_name': 'auth/logout.html', 'next_page':'home'}, name="logout"),

# Sub-projects
Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ Markdown==2.6.5

# For filters
PyExecJS==1.1.0

# For reaching out to OpenJUB
requests==2.12.3

# For authing against dreamjub
django-allauth==0.29.0
django-allauth-dreamjub==0.1.3
2 changes: 1 addition & 1 deletion templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<li role="presentation"><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li>
</ul>
{% else %}
<a href="{% url 'django.contrib.auth.views.login' %}">Login</a>
<a href="/accounts/dreamjub/login">Login</a>
{% endif %}
</li>
</ul>
Expand Down

0 comments on commit a3b229b

Please sign in to comment.