From 4a16009551be4ef27ad1f32631a4441263aacb05 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Tue, 17 Mar 2020 00:20:04 -0600 Subject: [PATCH] refactor: switching to pure allauth solution, addresses #13 & #2 --- accounts/forms.py | 7 --- cmdi/settings.py | 23 +++++++- cmdi/urls.py | 12 ++--- maps/templates/maps/footer.html | 4 +- maps/urls.py | 4 +- requirements.txt | 6 ++- templates/account/login.html | 53 +++++++++++++++++++ templates/account/logout.html | 28 ++++++++++ templates/account/password_reset.html | 30 +++++++++++ templates/account/signup.html | 27 ++++++++++ .../registration_form.html | 8 +-- 11 files changed, 175 insertions(+), 27 deletions(-) delete mode 100644 accounts/forms.py create mode 100644 templates/account/login.html create mode 100644 templates/account/logout.html create mode 100644 templates/account/password_reset.html create mode 100644 templates/account/signup.html diff --git a/accounts/forms.py b/accounts/forms.py deleted file mode 100644 index 609aa5c..0000000 --- a/accounts/forms.py +++ /dev/null @@ -1,7 +0,0 @@ -from django_registration.forms import RegistrationFormTermsOfService -from accounts.models import User - - -class UserRegistrationForm(RegistrationFormTermsOfService): - class Meta(RegistrationFormTermsOfService.Meta): - model = User diff --git a/cmdi/settings.py b/cmdi/settings.py index 582c41c..a65ecd1 100644 --- a/cmdi/settings.py +++ b/cmdi/settings.py @@ -52,12 +52,23 @@ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', + 'django.contrib.sites', 'django.contrib.staticfiles', 'django.contrib.gis', 'rest_framework', 'rest_framework_gis', 'django_countries', - 'django_registration', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + # 'allauth.socialaccount.providers.facebook', + # 'allauth.socialaccount.providers.github', + # 'allauth.socialaccount.providers.google', + # 'allauth.socialaccount.providers.instagram', + # 'allauth.socialaccount.providers.openid', + # 'allauth.socialaccount.providers.reddit', + 'allauth.socialaccount.providers.stackexchange', + # 'allauth.socialaccount.providers.twitter', 'accounts', 'mdi', 'maps', @@ -104,6 +115,15 @@ }, ] + +AUTHENTICATION_BACKENDS = ( + # Needed to login by username in Django admin, regardless of `allauth` + 'django.contrib.auth.backends.ModelBackend', + # `allauth` specific authentication methods, such as login by e-mail + 'allauth.account.auth_backends.AuthenticationBackend', +) +SITE_ID = 1 + WSGI_APPLICATION = 'cmdi.wsgi.application' @@ -113,7 +133,6 @@ AUTH_USER_MODEL = 'accounts.User' -ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window # Password validation diff --git a/cmdi/urls.py b/cmdi/urls.py index 1758f55..3571960 100644 --- a/cmdi/urls.py +++ b/cmdi/urls.py @@ -15,8 +15,7 @@ """ from django.contrib import admin from django.urls import path, include -from django_registration.backends.activation.views import RegistrationView -from accounts.forms import UserRegistrationForm +from django.conf.urls import url from rest_framework import routers from mdi.views import UserViewSet, GroupViewSet, OrganizationViewSet, SectorViewSet, ToolViewSet router = routers.DefaultRouter() @@ -31,13 +30,8 @@ path('admin/', admin.site.urls), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), path('maps/', include('maps.urls')), - path('accounts/register/', RegistrationView.as_view( - form_class=UserRegistrationForm - ), - name='django_registration_register', - ), - path('accounts/', include('django_registration.backends.activation.urls')), - path('accounts/', include('django.contrib.auth.urls')), + # path('accounts/', include('django.contrib.auth.urls')), + url(r'^accounts/', include('allauth.urls')), ] urlpatterns += [ path('', include(router.urls)) diff --git a/maps/templates/maps/footer.html b/maps/templates/maps/footer.html index f8e2368..a37070d 100644 --- a/maps/templates/maps/footer.html +++ b/maps/templates/maps/footer.html @@ -6,8 +6,8 @@ Platform Cooperativism Consortium
diff --git a/maps/urls.py b/maps/urls.py index 2d9ad62..d71e59e 100644 --- a/maps/urls.py +++ b/maps/urls.py @@ -8,6 +8,6 @@ path('profile/', views.profile, name='profile'), path('organizations/', views.organization_detail, name='organization_detail'), path('individuals/', views.individual_detail, name='individual_detail'), - path('privacy-policy/', PrivacyPolicyView.as_view(), {'name': 'privacy_policy', 'title': 'Privacy Policy'}), - path('terms-of-service/', TermsOfServiceView.as_view(), {'name': 'terms_of_service', 'title': 'Terms of Service'}), + path('privacy-policy/', PrivacyPolicyView.as_view(), {'title': 'Privacy Policy'}, name='privacy_policy'), + path('terms-of-service/', TermsOfServiceView.as_view(), {'title': 'Terms of Service'}, name='terms_of_service'), ] diff --git a/requirements.txt b/requirements.txt index 0e67bf5..4625e33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,12 +6,13 @@ chardet==3.0.4 confusable-homoglyphs==3.2.0 coreapi==2.3.3 coreschema==0.0.4 +defusedxml==0.6.0 dj-database-url==0.5.0 Django==3.0.3 +django-allauth==0.41.0 django-countries==5.5 django-dotenv==1.4.2 django-lockdown==3.0.0 -django-registration==3.1 django-ses==0.8.14 djangorestframework==3.11.0 djangorestframework-gis==0.15 @@ -28,13 +29,16 @@ jsonschema==3.2.0 Markdown==3.1.1 MarkupSafe==1.1.1 more-itertools==8.1.0 +oauthlib==3.1.0 packaging==20.0 psycopg2==2.8.4 pyparsing==2.4.6 pyrsistent==0.15.7 +python3-openid==3.1.0 pytz==2019.3 PyYAML==5.3 requests==2.22.0 +requests-oauthlib==1.3.0 ruamel.yaml==0.16.5 ruamel.yaml.clib==0.2.0 six==1.14.0 diff --git a/templates/account/login.html b/templates/account/login.html new file mode 100644 index 0000000..cc51096 --- /dev/null +++ b/templates/account/login.html @@ -0,0 +1,53 @@ +{% extends "account/base.html" %} + +{% load i18n %} +{% load account socialaccount %} + +{% block title %}{% trans "Sign In" %}{% endblock %} + +{% block content %} + + +{% get_providers as socialaccount_providers %} + +{% if socialaccount_providers %} +

{% blocktrans with site.name as site_name %}Please sign in with one +of your existing third party accounts. {% endblocktrans %}

+ +
+
    + {% include "socialaccount/snippets/provider_list.html" with process="login" %} +
+ + + +
+ +{% include "socialaccount/snippets/login_extra.html" %} + +{% else %} +

{% blocktrans %}If you have not created an account yet, then please +sign up first.{% endblocktrans %}

+{% endif %} + + + +{% endblock %} diff --git a/templates/account/logout.html b/templates/account/logout.html new file mode 100644 index 0000000..896799a --- /dev/null +++ b/templates/account/logout.html @@ -0,0 +1,28 @@ +{% extends "account/base.html" %} + +{% load i18n %} + +{% block head_title %}{% trans "Sign Out" %}{% endblock %} + +{% block content %} + + +

{% trans 'Are you sure you want to sign out?' %}

+ +
+ {% csrf_token %} + {% if redirect_field_value %} + + {% endif %} + +
+ + +
+ +{% endblock %} diff --git a/templates/account/password_reset.html b/templates/account/password_reset.html new file mode 100644 index 0000000..f1e4f6f --- /dev/null +++ b/templates/account/password_reset.html @@ -0,0 +1,30 @@ +{% extends "account/base.html" %} + +{% load i18n %} +{% load account %} + +{% block head_title %}{% trans "Password Reset" %}{% endblock %} + +{% block content %} + + + {% if user.is_authenticated %} + {% include "account/snippets/already_logged_in.html" %} + {% endif %} + +

{% trans "Forgotten your password? Enter your e-mail address below, and we'll send you an e-mail allowing you to reset it." %}

+ +
+ {% csrf_token %} + {{ form.as_p }} +
+ +
+ +

{% blocktrans %}Please contact us if you have any trouble resetting your password.{% endblocktrans %}

+{% endblock %} diff --git a/templates/account/signup.html b/templates/account/signup.html new file mode 100644 index 0000000..2abe348 --- /dev/null +++ b/templates/account/signup.html @@ -0,0 +1,27 @@ +{% extends "account/base.html" %} + +{% load i18n %} + +{% block head_title %}{% trans "Signup" %}{% endblock %} + +{% block content %} +

{% trans "Sign Up" %}

+ +

+ Accounts on the Directory are intended for parties working in the Platform Co-operative ecosystem: actively + managing organization profiles, doing academic or grantmaking research, or providing services such as + accounting, design, legal, or software development. Accounts are not required to browse the directory. +

+ +

{% blocktrans %}Already have an account? Then please sign in.{% endblocktrans %}

+ + + +{% endblock %} diff --git a/templates/django_registration/registration_form.html b/templates/django_registration/registration_form.html index 48de6fd..66c1cc9 100644 --- a/templates/django_registration/registration_form.html +++ b/templates/django_registration/registration_form.html @@ -11,16 +11,16 @@

Account creation

- Accounts on the Directory are intended for people working in the Platform Co-operative ecosystem: actively managing - organization profiles, doing academic or grantmaking research, or providing technical services. Accounts are not - necessary to browse the directory. + Accounts on the Directory are intended for parties working in the Platform Co-operative ecosystem: actively managing + organization profiles, doing academic or grantmaking research, or providing services such as accounting, design, + legal, or software development. Accounts are not required to browse the directory.

{% csrf_token %} -{{form}} +{{ form }}