From: Eevee Date: Tue, 10 Feb 2009 08:27:44 +0000 (-0800) Subject: Added a hook for sticking the logged-in user into c. X-Git-Tag: veekun-promotions/2010050901~13 X-Git-Url: http://git.veekun.com/zzz-spline-users.git/commitdiff_plain/546e4b9d5d72cfa36cca2f6f1d8f5cdc7225f329?ds=sidebyside;hp=efc8b2bfc9e8a98fe563608a9467d541fb99c614 Added a hook for sticking the logged-in user into c. --- diff --git a/spline/plugins/users/__init__.py b/spline/plugins/users/__init__.py index 6a0facf..53633d7 100644 --- a/spline/plugins/users/__init__.py +++ b/spline/plugins/users/__init__.py @@ -1,7 +1,29 @@ +from pylons import c, session + from spline.lib.plugin import PluginBase +import spline.model as model +import spline.model.meta as meta import controllers.accounts -import model +import model as user_model + +def check_userid_hook(action, **params): + """Hook to see if a user is logged in and, if so, stick a user object in + c. + """ + + if not 'user_id' in session: + return + + user = meta.Session.query(model.User).get(session['user_id']) + if not user: + # Bogus id in the session somehow. Clear it + del session['user_id'] + session.save() + return + + c.user = user + class UsersPlugin(PluginBase): def controllers(self): @@ -10,4 +32,9 @@ class UsersPlugin(PluginBase): ) def model(self): - return [model.User, model.OpenID] + return [user_model.User, user_model.OpenID] + + def hooks(self): + return [ + ('before_controller', 1, check_userid_hook), + ]