Ticket #599: issue_599.patch

File issue_599.patch, 2.0 KB (added by Jessica Tallon, 11 years ago)
  • mediagoblin/auth/forms.py

    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):  
    6464
    6565class LoginForm(wtforms.Form):
    6666    username = wtforms.TextField(
    67         _('Username'),
     67        _('Username or Email'),
    6868        [wtforms.validators.Required(),
    69          normalize_user_or_email_field(allow_email=False)])
     69         normalize_user_or_email_field()])
    7070    password = wtforms.PasswordField(
    7171        _('Password'),
    7272        [wtforms.validators.Required(),
  • mediagoblin/auth/views.py

    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  
    2525from mediagoblin.auth import forms as auth_forms
    2626from mediagoblin.auth.lib import send_verification_email, \
    2727                                 send_fp_verification_email
    28 
     28from sqlalchemy import or_
    2929
    3030def email_debug_message(request):
    3131    """
    def login(request):  
    113113    login_failed = False
    114114
    115115    if request.method == 'POST':
     116       
     117        username = login_form.data['username']
     118
    116119        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()
    118126
    119127            if user and user.check_login(login_form.password.data):
    120128                # set up login in session