From b1e02e0a702ffd085abdb5a4e1d3ca0b9c6192f1 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Mon, 27 May 2013 11:13:23 -0700 Subject: [PATCH] modified get_user function to take kwargs instead of username --- mediagoblin/auth/__init__.py | 5 +++-- mediagoblin/auth/tools.py | 2 +- mediagoblin/plugins/basic_auth/__init__.py | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mediagoblin/auth/__init__.py b/mediagoblin/auth/__init__.py index 8cb1f401..ab3d37e7 100644 --- a/mediagoblin/auth/__init__.py +++ b/mediagoblin/auth/__init__.py @@ -16,8 +16,9 @@ from mediagoblin.tools.pluginapi import hook_handle, hook_runall -def get_user(username): - return hook_handle("auth_get_user", username) +def get_user(**kwargs): + """ Takes a kwarg such as username and returns a user object """ + return hook_handle("auth_get_user", **kwargs) def create_user(register_form): diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py index 7123473d..e2c84347 100644 --- a/mediagoblin/auth/tools.py +++ b/mediagoblin/auth/tools.py @@ -199,7 +199,7 @@ def register_user(request, register_form): def check_login_simple(username, password): - user = auth.get_user(username) + user = auth.get_user(username=username) if not user: _log.info("User %r not found", username) auth.fake_login_attempt() diff --git a/mediagoblin/plugins/basic_auth/__init__.py b/mediagoblin/plugins/basic_auth/__init__.py index 375af335..71e96d73 100644 --- a/mediagoblin/plugins/basic_auth/__init__.py +++ b/mediagoblin/plugins/basic_auth/__init__.py @@ -26,17 +26,19 @@ def setup_plugin(): config = pluginapi.get_config('mediagoblin.pluginapi.basic_auth') -def get_user(username): - user = User.query.filter( - or_( - User.username == username, - User.email == username, - )).first() - return user +def get_user(**kwargs): + username = kwargs.pop('username', None) + if 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.username.data) + user = get_user(username=registration_form.username.data) if not user and 'password' in registration_form: user = User() user.username = registration_form.username.data -- 2.25.1