modified get_user function to take kwargs instead of username
authorRodney Ewing <ewing.rj@gmail.com>
Mon, 27 May 2013 18:13:23 +0000 (11:13 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Mon, 27 May 2013 18:14:08 +0000 (11:14 -0700)
mediagoblin/auth/__init__.py
mediagoblin/auth/tools.py
mediagoblin/plugins/basic_auth/__init__.py

index 8cb1f40188afc0347435d704ef8c55f0d3424c2c..ab3d37e7c2e0d00b381a85fb5711d82506ff7399 100644 (file)
@@ -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):
index 7123473d22bac7638b8f87bd9bb0d905fdc23d18..e2c84347151b142c30d53aac2ae2370169e0e4d2 100644 (file)
@@ -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()
index 375af33562666eb0184b9c096a345fa21ba3bdbf..71e96d73cc1cf6b54d9b6ef862a26ba75318c396 100644 (file)
@@ -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