From 546e4b9d5d72cfa36cca2f6f1d8f5cdc7225f329 Mon Sep 17 00:00:00 2001 From: Eevee Date: Tue, 10 Feb 2009 00:27:44 -0800 Subject: [PATCH] Added a hook for sticking the logged-in user into c. --- spline/plugins/users/__init__.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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), + ] -- 2.7.4