diff --git a/pinaxcon/account_hooks.py b/pinaxcon/account_hooks.py new file mode 100644 index 0000000000000000000000000000000000000000..6f2b0dde7857bfd9c6ce5f393cc4f7e88a828134 --- /dev/null +++ b/pinaxcon/account_hooks.py @@ -0,0 +1,25 @@ +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