From a3b229b48c1e9405707898b99fa36a20e1be3be0 Mon Sep 17 00:00:00 2001 From: Leonhard Kuboschek Date: Fri, 10 Mar 2017 13:43:38 +0100 Subject: [PATCH] Fixes part of #26. Authentication with Dreamjub works. --- core/views.py | 10 ++++++++-- jay/settings.py | 17 +++++++++++++++-- jay/urls.py | 2 +- requirements.txt | 7 +++++++ templates/base/base.html | 2 +- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/views.py b/core/views.py index 35c067d..c45215b 100644 --- a/core/views.py +++ b/core/views.py @@ -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" diff --git a/jay/settings.py b/jay/settings.py index 60aacbe..aa4bb87 100644 --- a/jay/settings.py +++ b/jay/settings.py @@ -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', @@ -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 @@ -93,3 +103,6 @@ ) STATIC_URL = '/static/' +SITE_ID = 1 + +ACCOUNT_EMAIL_VERIFICATION = "none" \ No newline at end of file diff --git a/jay/urls.py b/jay/urls.py index 37c9f9a..058ecd2 100644 --- a/jay/urls.py +++ b/jay/urls.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 43dde12..d6d0641 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/templates/base/base.html b/templates/base/base.html index e740a8a..ae85eee 100644 --- a/templates/base/base.html +++ b/templates/base/base.html @@ -67,7 +67,7 @@
  • Logout
  • {% else %} - Login + Login {% endif %}