From cdc6b571e33ee0cd90fa8f2be270df77d7f6d9d9 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Mon, 27 May 2013 08:39:34 -0700 Subject: [PATCH] cleanup after merge --- mediagoblin/auth/__init__.py | 4 ++-- mediagoblin/auth/tools.py | 9 +++------ mediagoblin/auth/views.py | 3 +-- mediagoblin/plugins/basic_auth/__init__.py | 18 ++++++++---------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/mediagoblin/auth/__init__.py b/mediagoblin/auth/__init__.py index 53182eaa..ae6c4b96 100644 --- a/mediagoblin/auth/__init__.py +++ b/mediagoblin/auth/__init__.py @@ -23,8 +23,8 @@ def check_login(user, password): return False -def get_user(form): - return hook_handle("auth_get_user", form) +def get_user(username): + return hook_handle("auth_get_user", username) def create_user(register_form): diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py index f38a292a..94a9781b 100644 --- a/mediagoblin/auth/tools.py +++ b/mediagoblin/auth/tools.py @@ -199,15 +199,12 @@ def send_fp_verification_email(user, request): def check_login_simple(username, password, username_might_be_email=False): - search = (User.username == username) - if username_might_be_email and ('@' in username): - search = or_(search, User.email == username) - user = User.query.filter(search).first() + user = auth.get_user(username) if not user: _log.info("User %r not found", username) - auth_lib.fake_login_attempt() + auth.fake_login_attempt() return None - if not auth_lib.bcrypt_check_password(password, user.pw_hash): + if not auth.check_password(password, user.pw_hash): _log.warn("Wrong password for %r", username) return None _log.info("Logging %r in", username) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 109763ce..b62602b3 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -22,7 +22,6 @@ from mediagoblin.db.models import User from mediagoblin.tools.response import render_to_response, redirect, render_404 from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.mail import email_debug_message -from mediagoblin.auth import lib as auth_lib from mediagoblin.auth import forms as auth_forms from mediagoblin.auth.tools import (send_verification_email, register_user, @@ -301,7 +300,7 @@ def verify_forgot_password(request): cp_form = auth_forms.ChangePassForm(formdata_vars) if request.method == 'POST' and cp_form.validate(): - user.pw_hash = auth_lib.bcrypt_gen_password_hash( + user.pw_hash = auth.gen_password_hash( cp_form.password.data) user.fp_verification_key = None user.fp_token_expire = None diff --git a/mediagoblin/plugins/basic_auth/__init__.py b/mediagoblin/plugins/basic_auth/__init__.py index 2fe161cb..edbfacb5 100644 --- a/mediagoblin/plugins/basic_auth/__init__.py +++ b/mediagoblin/plugins/basic_auth/__init__.py @@ -34,19 +34,17 @@ def check_login(user, password): return None -def get_user(form): - if 'username' in form.data: - username = form.username.data - user = User.query.filter( - or_( - User.username == username, - User.email == username, - )).first() - return user +def get_user(username): + user = User.query.filter( + or_( + User.username == username, + User.email == username, + )).first() + return user def create_user(registration_form): - user = get_user(registration_form) + user = get_user(registration_form.username.data) if not user and 'password' in registration_form: user = User() user.username = registration_form.username.data -- 2.25.1