Dead simple user list.
[zzz-spline-users.git] / spline / plugins / users / __init__.py
1 from pkg_resources import resource_filename
2
3 from pylons import c, session
4
5 from spline.lib.plugin import PluginBase
6 from spline.lib.plugin import PluginBase, PluginLink, Priority
7 import spline.model as model
8 import spline.model.meta as meta
9
10 import spline.plugins.users.controllers.accounts
11 import spline.plugins.users.controllers.users
12 import spline.plugins.users.model
13
14 def add_routes_hook(map, *args, **kwargs):
15 """Hook to inject some of our behavior into the routes configuration."""
16 # Login, logout
17 map.connect('/accounts/login', controller='accounts', action='login')
18 map.connect('/accounts/login_begin', controller='accounts', action='login_begin')
19 map.connect('/accounts/login_finish', controller='accounts', action='login_finish')
20 map.connect('/accounts/logout', controller='accounts', action='logout')
21
22 # Self-admin
23 map.connect('/users/{id};{name}/edit', controller='users', action='profile_edit')
24
25 # Public user pages
26 map.connect('/users', controller='users', action='list')
27 map.connect('/users/{id};{name}', controller='users', action='profile')
28 map.connect('/users/{id}', controller='users', action='profile')
29
30 def check_userid_hook(action, **params):
31 """Hook to see if a user is logged in and, if so, stick a user object in
32 c.
33 """
34
35 c.user = None
36
37 if not 'user_id' in session:
38 return
39
40 user = meta.Session.query(model.User).get(session['user_id'])
41 if not user:
42 # Bogus id in the session somehow. Clear it
43 del session['user_id']
44 session.save()
45 return
46
47 c.user = user
48
49
50 class UsersPlugin(PluginBase):
51 def controllers(self):
52 return dict(
53 accounts = spline.plugins.users.controllers.accounts.AccountsController,
54 users = spline.plugins.users.controllers.users.UsersController,
55 )
56
57 def model(self):
58 return [
59 spline.plugins.users.model.User,
60 spline.plugins.users.model.OpenID,
61 ]
62
63 def template_dirs(self):
64 return [
65 (resource_filename(__name__, 'templates'), Priority.NORMAL)
66 ]
67
68 def hooks(self):
69 return [
70 ('routes_mapping', Priority.NORMAL, add_routes_hook),
71 ('before_controller', Priority.VERY_FIRST, check_userid_hook),
72 ]
73
74 def widgets(self):
75 return [
76 ('page_header', Priority.NORMAL, 'widgets/user_state.mako'),
77 ]