"""Hook to inject some of our behavior into the routes configuration."""
map.connect('/accounts/login_begin', controller='accounts', action='login_begin')
map.connect('/accounts/login_finish', controller='accounts', action='login_finish')
+ map.connect('/accounts/logout', controller='accounts', action='logout')
def check_userid_hook(action, **params):
"""Hook to see if a user is logged in and, if so, stick a user object in
from spline import model
from spline.model import meta
+from spline.lib import helpers as h
from spline.lib.base import BaseController, render
log = logging.getLogger(__name__)
session['user_id'] = user.id
session.save()
- redirect_to(url('/'))
+ h.flash(u"""Hello, {0}!""".format(user.name),
+ icon='user')
+
+ redirect_to('/', _code=303)
+
+ def logout(self):
+ """Logs the user out."""
+
+ if 'user_id' in session:
+ del session['user_id']
+ session.save()
+
+ h.flash(u"""Logged out.""",
+ icon='user-silhouette')
+
+ redirect_to('/', _code=303)
-${h.form(url(controller='accounts', action='login_begin'), id='user')}
- % if c.user:
+% if c.user:
+${h.form(url(controller='accounts', action='logout'), id='user')}
Logged in as ${c.user.name}.
- % else:
+ <input type="submit" value="Log out">
+${h.end_form()}
+% else:
+${h.form(url(controller='accounts', action='login_begin'), id='user')}
<img src="${h.static_uri('spline', 'icons/openid.png')}">
<input type="text" name="openid" size="30">
<input type="submit" value="Log in">
- % endif
${h.end_form()}
+% endif