Permalink
Browse files

Merge pull request #128 from HorizonShadow/login_case-fix

Make login username case insensitive
  • Loading branch information...
svenstaro committed Jun 18, 2014
2 parents 16bd113 + 04bd4bf commit bb9fc04f649d63da96e105d8a59efe81b1022868
Showing with 7 additions and 5 deletions.
  1. +5 −4 flamejam/forms.py
  2. +2 −1 flamejam/views/account.py
View
@@ -10,6 +10,7 @@
import re
from flamejam import app, models, utils
from flamejam.models.rating import RATING_CATEGORIES
+from sqlalchemy import func
############## VALIDATORS ####################
@@ -40,13 +41,13 @@ def __call__(self, form, field):
class UsernameExists(object):
def __call__(self, form, field):
- u = models.User.query.filter_by(username = field.data).first()
+ u = models.User.query.filter(func.lower(models.User.username) == func.lower(field.data)).first()
if not u:
raise ValidationError("The username does not exist.")
class EmailExists(object):
def __call__(self, form, field):
- e = models.User.query.filter_by(email = field.data).first()
+ e = models.User.query.filter(func.lower(models.User.email) == func.lower(field.data)).first()
if not e:
raise ValidationError("That email does not exist")
@@ -57,7 +58,7 @@ def __init__(self, pw_field, message_username = "The username or password is inc
self.message_password = message_password
def __call__(self, form, field):
- u = models.User.query.filter_by(username = field.data).first()
+ u = models.User.query.filter(func.lower(models.User.username) == func.lower(field.data)).first()
if not u:
raise ValidationError(self.message_username)
elif not utils.verify_password(u.password, form[self.pw_field].data):
@@ -68,7 +69,7 @@ def __init__(self, message_username = "The username is incorrect."):
self.message_username = message_username
def __call__(self, form, field):
- u = models.User.query.filter_by(username = field.data).first()
+ u = models.User.query.filter(func.lower(models.User.username) == func.lower(field.data)).first()
if not u:
raise ValidationError(self.message_username)
@@ -8,6 +8,7 @@
from flask import render_template, redirect, flash, url_for, current_app, session, request, abort, Markup
from flask.ext.login import login_required, login_user, logout_user, current_user
from flask.ext.principal import AnonymousIdentity, Identity, UserNeed, identity_changed, identity_loaded, Permission, RoleNeed, PermissionDenied
+from sqlalchemy import func
@app.route('/login', methods=['GET', 'POST'])
def login():
@@ -18,7 +19,7 @@ def login():
username = login_form.username.data
password = login_form.password.data
remember_me = login_form.remember_me.data
- user = User.query.filter_by(username=username).first()
+ user = User.query.filter(func.lower(User.username) == func.lower(username)).first()
if login_user(user, remember_me):
flash("You were logged in.", "success")
if user.invitations.count():

0 comments on commit bb9fc04

Please sign in to comment.