modified get_user function to take kwargs instead of username

This commit is contained in:
Rodney Ewing 2013-05-27 11:13:23 -07:00
parent f81206df31
commit b1e02e0a70
3 changed files with 14 additions and 11 deletions

View File

@ -16,8 +16,9 @@
from mediagoblin.tools.pluginapi import hook_handle, hook_runall from mediagoblin.tools.pluginapi import hook_handle, hook_runall
def get_user(username): def get_user(**kwargs):
return hook_handle("auth_get_user", username) """ Takes a kwarg such as username and returns a user object """
return hook_handle("auth_get_user", **kwargs)
def create_user(register_form): def create_user(register_form):

View File

@ -199,7 +199,7 @@ def register_user(request, register_form):
def check_login_simple(username, password): def check_login_simple(username, password):
user = auth.get_user(username) user = auth.get_user(username=username)
if not user: if not user:
_log.info("User %r not found", username) _log.info("User %r not found", username)
auth.fake_login_attempt() auth.fake_login_attempt()

View File

@ -26,17 +26,19 @@ def setup_plugin():
config = pluginapi.get_config('mediagoblin.pluginapi.basic_auth') config = pluginapi.get_config('mediagoblin.pluginapi.basic_auth')
def get_user(username): def get_user(**kwargs):
user = User.query.filter( username = kwargs.pop('username', None)
or_( if username:
User.username == username, user = User.query.filter(
User.email == username, or_(
)).first() User.username == username,
return user User.email == username,
)).first()
return user
def create_user(registration_form): def create_user(registration_form):
user = get_user(registration_form.username.data) user = get_user(username=registration_form.username.data)
if not user and 'password' in registration_form: if not user and 'password' in registration_form:
user = User() user = User()
user.username = registration_form.username.data user.username = registration_form.username.data