Changeset - 0487525f5c26
[Not reviewed]
0 4 1
Christopher Neugebauer - 7 years ago 2017-08-18 16:26:35
chrisjrn@gmail.com
Lets us log in by email (badly)
5 files changed with 36 insertions and 3 deletions:
0 comments (0 inline, 0 general)
pinaxcon/account_hooks.py
Show inline comments
 
new file 100644
 
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
pinaxcon/settings.py
Show inline comments
...
 
@@ -274,2 +274,3 @@ ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2
 
ACCOUNT_USE_AUTH_AUTHENTICATE = True
 
ACCOUNT_HOOKSET =  "pinaxcon.account_hooks.BetterAccountHookSet"
 

	
pinaxcon/templates/account_login.html
Show inline comments
...
 
@@ -17,3 +17,3 @@
 

	
 
        <form action="{% url 'account_login' %}" method="POST">
 
        <form action="{% url 'nbpy_login_handle' %}" method="POST">
 
          <div class="panel panel-primary">
...
 
@@ -26,3 +26,3 @@
 
              {% csrf_token %}
 
              {{ login_form| bootstrap }}
 
              {{ login_form|bootstrap }}
 
            </div>
pinaxcon/urls.py
Show inline comments
...
 
@@ -55,2 +55,3 @@ urlpatterns = [
 
    url(r"^login$", views.account_login, name="nbpy_login"),
 
    url(r"^login_handle$", views.EmailLoginView.as_view(), name="nbpy_login_handle"),
 
    url(r"^account/", include("account.urls")),
pinaxcon/views.py
Show inline comments
...
 
@@ -9,2 +9,3 @@ from django.views import defaults
 
from account.forms import LoginEmailForm, LoginUsernameForm, SignupForm
 
from account.views import LoginView
 

	
...
 
@@ -18,3 +19,3 @@ def account_login(request):
 
    d = {
 
        "login_form": LoginUsernameForm(),
 
        "login_form": LoginEmailForm(),
 
        "signup_form": SignupForm(),
...
 
@@ -25 +26,5 @@ def account_login(request):
 
    return render(request, "account_login.html", d)
 

	
 

	
 
class EmailLoginView(LoginView):
 
    form_class = LoginEmailForm
0 comments (0 inline, 0 general)