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
...
 
@@ -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",
pinaxcon/templates/account_login.html
Show inline comments
...
 
@@ -15,7 +15,7 @@
 
    <div class="row">
 
      <div class="col-md-4">
 

	
 
        <form action="{% url 'account_login' %}" method="POST">
 
        <form action="{% url 'nbpy_login_handle' %}" method="POST">
 
          <div class="panel panel-primary">
 
            <div class="panel-heading">
 
              <h3 class="panel-title">
...
 
@@ -24,7 +24,7 @@
 
            </div>
 
            <div class="panel-body">
 
              {% csrf_token %}
 
              {{ login_form| bootstrap }}
 
              {{ login_form|bootstrap }}
 
            </div>
 
            <div class="panel-footer">
 
              <button role="submit" class="btn btn-primary">Log In</button>
pinaxcon/urls.py
Show inline comments
...
 
@@ -53,6 +53,7 @@ urlpatterns = [
 
    url(r"^admin/", include(admin.site.urls)),
 

	
 
    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")),
 

	
 
    url(r"^dashboard/", symposion.views.dashboard, name="dashboard"),
pinaxcon/views.py
Show inline comments
...
 
@@ -7,6 +7,7 @@ from django.template.loader import get_template
 
from django.views import defaults
 

	
 
from account.forms import LoginEmailForm, LoginUsernameForm, SignupForm
 
from account.views import LoginView
 

	
 
def server_error(request, template_name=defaults.ERROR_500_TEMPLATE_NAME):
 
    t = Template("{%% include '%s' %%}" % template_name)
...
 
@@ -16,10 +17,14 @@ def server_error(request, template_name=defaults.ERROR_500_TEMPLATE_NAME):
 
def account_login(request):
 

	
 
    d = {
 
        "login_form": LoginUsernameForm(),
 
        "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)
 

	
 

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