From b2c8dbcf8507811fe931a48722ed9c8b530bcdae Mon Sep 17 00:00:00 2001
From: Jessica T <xray7224@googlemail.com>
Date: Fri, 12 Apr 2013 22:07:44 +0100
Subject: [PATCH] Allows you to use your username or email to login
---
mediagoblin/auth/forms.py | 4 ++--
mediagoblin/auth/views.py | 12 ++++++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/mediagoblin/auth/forms.py b/mediagoblin/auth/forms.py
index 8f091d2..5484c17 100644
a
|
b
|
class RegistrationForm(wtforms.Form):
|
64 | 64 | |
65 | 65 | class LoginForm(wtforms.Form): |
66 | 66 | username = wtforms.TextField( |
67 | | _('Username'), |
| 67 | _('Username or Email'), |
68 | 68 | [wtforms.validators.Required(), |
69 | | normalize_user_or_email_field(allow_email=False)]) |
| 69 | normalize_user_or_email_field()]) |
70 | 70 | password = wtforms.PasswordField( |
71 | 71 | _('Password'), |
72 | 72 | [wtforms.validators.Required(), |
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
index 354b48c..dc40891 100644
a
|
b
|
from mediagoblin.auth import lib as auth_lib
|
25 | 25 | from mediagoblin.auth import forms as auth_forms |
26 | 26 | from mediagoblin.auth.lib import send_verification_email, \ |
27 | 27 | send_fp_verification_email |
28 | | |
| 28 | from sqlalchemy import or_ |
29 | 29 | |
30 | 30 | def email_debug_message(request): |
31 | 31 | """ |
… |
… |
def login(request):
|
113 | 113 | login_failed = False |
114 | 114 | |
115 | 115 | if request.method == 'POST': |
| 116 | |
| 117 | username = login_form.data['username'] |
| 118 | |
116 | 119 | if login_form.validate(): |
117 | | user = User.query.filter_by(username=login_form.data['username']).first() |
| 120 | user = User.query.filter( |
| 121 | or_( |
| 122 | User.username == username, |
| 123 | User.email == username, |
| 124 | |
| 125 | )).first() |
118 | 126 | |
119 | 127 | if user and user.check_login(login_form.password.data): |
120 | 128 | # set up login in session |