Allows you to use your username or email to login
authorJessica T <xray7224@googlemail.com>
Fri, 12 Apr 2013 21:07:44 +0000 (22:07 +0100)
committerJessica T <xray7224@googlemail.com>
Fri, 12 Apr 2013 21:07:44 +0000 (22:07 +0100)
mediagoblin/auth/forms.py
mediagoblin/auth/views.py

index 8f091d2143a5aaae8586cb380a25cca606ccb9b3..5484c178bf9158d5ba92309c19a628864a34d3d5 100644 (file)
@@ -64,9 +64,9 @@ class RegistrationForm(wtforms.Form):
 
 class LoginForm(wtforms.Form):
     username = wtforms.TextField(
-        _('Username'),
+        _('Username or Email'),
         [wtforms.validators.Required(),
-         normalize_user_or_email_field(allow_email=False)])
+         normalize_user_or_email_field()])
     password = wtforms.PasswordField(
         _('Password'),
         [wtforms.validators.Required(),
index 354b48c1ab08ac6ec4bd4b7d6d6f16e208246765..dc408911347d21dacb90395fd39a5f5414e1cb72 100644 (file)
@@ -25,7 +25,7 @@ from mediagoblin.auth import lib as auth_lib
 from mediagoblin.auth import forms as auth_forms
 from mediagoblin.auth.lib import send_verification_email, \
                                  send_fp_verification_email
-
+from sqlalchemy import or_
 
 def email_debug_message(request):
     """
@@ -113,8 +113,16 @@ def login(request):
     login_failed = False
 
     if request.method == 'POST':
+        
+        username = login_form.data['username']
+
         if login_form.validate():
-            user = User.query.filter_by(username=login_form.data['username']).first()
+            user = User.query.filter(
+                or_(
+                    User.username == username,
+                    User.email == username,
+
+                )).first()
 
             if user and user.check_login(login_form.password.data):
                 # set up login in session