projects
/
zzz-spline-users.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
efc8b2b
)
Added a hook for sticking the logged-in user into c.
author
Eevee
<git@veekun.com>
Tue, 10 Feb 2009 08:27:44 +0000
(
00:27
-0800)
committer
Eevee
<git@veekun.com>
Tue, 10 Feb 2009 08:27:44 +0000
(
00:27
-0800)
spline/plugins/users/__init__.py
patch
|
blob
|
history
diff --git
a/spline/plugins/users/__init__.py
b/spline/plugins/users/__init__.py
index
6a0facf
..
53633d7
100644
(file)
--- 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
from spline.lib.plugin import PluginBase
+import spline.model as model
+import spline.model.meta as meta
import controllers.accounts
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):
class UsersPlugin(PluginBase):
def controllers(self):
@@
-10,4
+32,9
@@
class UsersPlugin(PluginBase):
)
def model(self):
)
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),
+ ]