From 0487525f5c26d1d5d8ab50f471d6ec7a3416a57a Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 18 Aug 2017 09:26:35 -0700 Subject: [PATCH] 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 }}