Lets us log in by email (badly)
This commit is contained in:
parent
1743a6e9ae
commit
0487525f5c
5 changed files with 36 additions and 3 deletions
26
pinaxcon/account_hooks.py
Normal file
26
pinaxcon/account_hooks.py
Normal file
|
@ -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
|
|
@ -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",
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue