From ce77ac6b5c69406f1e880e416ec2d7ae6d874245 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 18 Aug 2017 08:10:03 -0700 Subject: [PATCH 1/7] Fixes #67 --- pinaxcon/settings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pinaxcon/settings.py b/pinaxcon/settings.py index 2d744d5..1ee7dde 100644 --- a/pinaxcon/settings.py +++ b/pinaxcon/settings.py @@ -15,7 +15,7 @@ DATABASES = { } } -UNPREPEND_WWW = bool(os.environ.get("DJANGO_UNPREPEND_WWW", False)) +UNPREPEND_WWW = bool(int(os.environ.get("DJANGO_UNPREPEND_WWW", "0"))) # HEROKU: Update database configuration with $DATABASE_URL. import dj_database_url @@ -258,11 +258,12 @@ EMAIL_HOST = os.environ.get("DJANGO_EMAIL_HOST", "") EMAIL_PORT = int(os.environ.get("DJANGO_EMAIL_PORT", 25)) EMAIL_HOST_USER = os.environ.get("DJANGO_EMAIL_HOST_USER", "") EMAIL_HOST_PASSWORD = os.environ.get("DJANGO_EMAIL_HOST_PASSWORD", "") -EMAIL_USE_TLS = bool(os.environ.get("DJANGO_EMAIL_USE_TLS", False)) -EMAIL_USE_SSL = bool(os.environ.get("DJANGO_EMAIL_USE_SSL", False)) +EMAIL_USE_TLS = bool(int(os.environ.get("DJANGO_EMAIL_USE_TLS", "0"))) +EMAIL_USE_SSL = bool(int(os.environ.get("DJANGO_EMAIL_USE_SSL", "0"))) + # We need to explicitly switch on signups. -ACCOUNT_OPEN_SIGNUP = bool(os.environ.get("DJANGO_ACCOUNT_OPEN_SIGNUP", False)) +ACCOUNT_OPEN_SIGNUP = bool(int(os.environ.get("DJANGO_ACCOUNT_OPEN_SIGNUP", "0"))) ACCOUNT_EMAIL_UNIQUE = True ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = False if DEBUG else True ACCOUNT_LOGIN_REDIRECT_URL = "home" From a6cf86f826542baeb9bfa948916776ef8a517a62 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 18 Aug 2017 08:46:51 -0700 Subject: [PATCH 2/7] Adds new combined login & signup view --- pinaxcon/settings.py | 2 + pinaxcon/templates/account_login.html | 59 +++++++++++++++++++++++++++ pinaxcon/urls.py | 1 + pinaxcon/views.py | 18 ++++++++ 4 files changed, 80 insertions(+) create mode 100644 pinaxcon/templates/account_login.html diff --git a/pinaxcon/settings.py b/pinaxcon/settings.py index 1ee7dde..8501577 100644 --- a/pinaxcon/settings.py +++ b/pinaxcon/settings.py @@ -261,6 +261,8 @@ EMAIL_HOST_PASSWORD = os.environ.get("DJANGO_EMAIL_HOST_PASSWORD", "") EMAIL_USE_TLS = bool(int(os.environ.get("DJANGO_EMAIL_USE_TLS", "0"))) EMAIL_USE_SSL = bool(int(os.environ.get("DJANGO_EMAIL_USE_SSL", "0"))) +ACCOUNT_LOGIN_URL = "nbpy_login" +LOGIN_URL = "nbpy_login" # We need to explicitly switch on signups. ACCOUNT_OPEN_SIGNUP = bool(int(os.environ.get("DJANGO_ACCOUNT_OPEN_SIGNUP", "0"))) diff --git a/pinaxcon/templates/account_login.html b/pinaxcon/templates/account_login.html new file mode 100644 index 0000000..59f0bbc --- /dev/null +++ b/pinaxcon/templates/account_login.html @@ -0,0 +1,59 @@ +{% extends "page_with_title_and_lede.html" %} + +{% load bootstrap %} +{% load i18n %} + +{% block head_title %}Log In{% endblock %} + +{% block heading %}Log In or Sign Up{% endblock %} + +{% block body_class %}login{% endblock %} + +{% block content %} + +
+
+
+ +
+
+
+

+ Log into an existing account +

+
+
+ {% csrf_token %} + {{ login_form| bootstrap }} +
+ +
+
+ +
+ {% if signup_open %} +
+
+
+
+

+ Sign up for a new account +

+
+
+ {% csrf_token %} + {{ signup_form|bootstrap }} +
+ +
+
+
+ {% endif %} +
+
+ +{% endblock %} diff --git a/pinaxcon/urls.py b/pinaxcon/urls.py index 6f454a8..534792f 100644 --- a/pinaxcon/urls.py +++ b/pinaxcon/urls.py @@ -52,6 +52,7 @@ urlpatterns = [ url(r"^admin/", include(admin.site.urls)), + url(r"^login$", views.account_login, name="nbpy_login"), url(r"^account/", include("account.urls")), url(r"^dashboard/", symposion.views.dashboard, name="dashboard"), diff --git a/pinaxcon/views.py b/pinaxcon/views.py index 433e368..734508a 100644 --- a/pinaxcon/views.py +++ b/pinaxcon/views.py @@ -1,9 +1,27 @@ +from django.conf import settings from django.http import HttpResponseServerError +from django.shortcuts import render from django.template import RequestContext from django.template import Template from django.template.loader import get_template from django.views import defaults +from account.forms import LoginEmailForm, LoginUsernameForm, SignupForm + def server_error(request, template_name=defaults.ERROR_500_TEMPLATE_NAME): t = Template("{%% include '%s' %%}" % template_name) return HttpResponseServerError(t.render(RequestContext(request))) + + +def account_login(request): + + d = { + "login_form": LoginEmailForm(), + "signup_form": SignupForm(), + "signup_open": getattr(settings, "ACCOUNT_OPEN_SIGNUP", True), + } + + print d["signup_open"], settings.ACCOUNT_OPEN_SIGNUP + return render(request, "account_login.html", d) + + From 1743a6e9ae7967267af16ca4f7b5b809b5f578c4 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 18 Aug 2017 08:55:32 -0700 Subject: [PATCH 3/7] (Actually Works) --- pinaxcon/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pinaxcon/views.py b/pinaxcon/views.py index 734508a..34b8d23 100644 --- a/pinaxcon/views.py +++ b/pinaxcon/views.py @@ -16,12 +16,10 @@ def server_error(request, template_name=defaults.ERROR_500_TEMPLATE_NAME): def account_login(request): d = { - "login_form": LoginEmailForm(), + "login_form": LoginUsernameForm(), "signup_form": SignupForm(), "signup_open": getattr(settings, "ACCOUNT_OPEN_SIGNUP", True), } print d["signup_open"], settings.ACCOUNT_OPEN_SIGNUP return render(request, "account_login.html", d) - - From 0487525f5c26d1d5d8ab50f471d6ec7a3416a57a Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 18 Aug 2017 09:26:35 -0700 Subject: [PATCH 4/7] Lets us log in by email (badly) --- pinaxcon/account_hooks.py | 26 ++++++++++++++++++++++++++ pinaxcon/settings.py | 1 + pinaxcon/templates/account_login.html | 4 ++-- pinaxcon/urls.py | 1 + pinaxcon/views.py | 7 ++++++- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 pinaxcon/account_hooks.py diff --git a/pinaxcon/account_hooks.py b/pinaxcon/account_hooks.py new file mode 100644 index 0000000..e3affff --- /dev/null +++ b/pinaxcon/account_hooks.py @@ -0,0 +1,26 @@ +from account import hooks +from django.contrib.auth.models import User + + +class BetterAccountHookSet(hooks.AccountDefaultHookSet): + + def get_user_credentials(self, form, identifier_field): + username = form.cleaned_data[identifier_field] + + # Find an actual username so we can authenticate + print username, + if identifier_field == "email": + username = self.get_username_by_email(username) + print username, + + return { + "username": username, + "password": form.cleaned_data["password"], + } + + def get_username_by_email(self, email): + + try: + return User.objects.get(email=email).username + except User.DoesNotExist: + return None diff --git a/pinaxcon/settings.py b/pinaxcon/settings.py index 8501577..0e39def 100644 --- a/pinaxcon/settings.py +++ b/pinaxcon/settings.py @@ -272,6 +272,7 @@ ACCOUNT_LOGIN_REDIRECT_URL = "home" ACCOUNT_LOGOUT_REDIRECT_URL = "home" ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2 ACCOUNT_USE_AUTH_AUTHENTICATE = True +ACCOUNT_HOOKSET = "pinaxcon.account_hooks.BetterAccountHookSet" AUTHENTICATION_BACKENDS = [ "symposion.teams.backends.TeamPermissionsBackend", diff --git a/pinaxcon/templates/account_login.html b/pinaxcon/templates/account_login.html index 59f0bbc..a660e25 100644 --- a/pinaxcon/templates/account_login.html +++ b/pinaxcon/templates/account_login.html @@ -15,7 +15,7 @@
-
+

@@ -24,7 +24,7 @@

{% csrf_token %} - {{ login_form| bootstrap }} + {{ login_form|bootstrap }}