1 from pkg_resources
import resource_filename
3 from pylons
import c
, session
5 from spline
.lib
.plugin
import PluginBase
6 from spline
.lib
.plugin
import PluginBase
, PluginLink
, Priority
7 import spline
.model
.meta
as meta
9 import splinext
.users
.controllers
.accounts
10 import splinext
.users
.controllers
.users
11 from splinext
.users
import model
as users_model
13 def add_routes_hook(map, *args
, **kwargs
):
14 """Hook to inject some of our behavior into the routes configuration."""
15 def id_is_numeric(environ
, result
):
19 except (KeyError, ValueError):
23 map.connect('/accounts/login', controller
='accounts', action
='login')
24 map.connect('/accounts/login_begin', controller
='accounts', action
='login_begin')
25 map.connect('/accounts/login_finish', controller
='accounts', action
='login_finish')
26 map.connect('/accounts/logout', controller
='accounts', action
='logout')
29 map.connect('/users/{id};{name}/edit', controller
='users', action
='profile_edit',
30 conditions
=dict(function
=id_is_numeric
))
33 map.connect('/users', controller
='users', action
='list')
34 map.connect('/users/{id};{name}', controller
='users', action
='profile',
35 conditions
=dict(function
=id_is_numeric
))
36 map.connect('/users/{id}', controller
='users', action
='profile',
37 conditions
=dict(function
=id_is_numeric
))
39 def check_userid_hook(action
, **params
):
40 """Hook to see if a user is logged in and, if so, stick a user object in
44 if not 'user_id' in session
:
45 c
.user
= users_model
.AnonymousUser()
48 user
= meta
.Session
.query(users_model
.User
).get(session
['user_id'])
50 # Bogus id in the session somehow. Clear it
51 del session
['user_id']
54 c
.user
= users_model
.AnonymousUser()
60 class UsersPlugin(PluginBase
):
61 def controllers(self
):
63 accounts
= splinext
.users
.controllers
.accounts
.AccountsController
,
64 users
= splinext
.users
.controllers
.users
.UsersController
,
67 def template_dirs(self
):
69 (resource_filename(__name__
, 'templates'), Priority
.NORMAL
)
74 ('routes_mapping', Priority
.NORMAL
, add_routes_hook
),
75 ('before_controller', Priority
.VERY_FIRST
, check_userid_hook
),
80 ('page_header', Priority
.NORMAL
, 'widgets/user_state.mako'),