From: Eevee Date: Thu, 22 Apr 2010 07:02:25 +0000 (-0700) Subject: Implemented logout and generally fixed the in/out sequence. #69 X-Git-Tag: veekun-promotions/2010050901~8 X-Git-Url: http://git.veekun.com/zzz-spline-users.git/commitdiff_plain/f825759a785c954986b6344cb643aa075c3849f3?ds=inline Implemented logout and generally fixed the in/out sequence. #69 --- diff --git a/spline/plugins/users/__init__.py b/spline/plugins/users/__init__.py index 92a825c..5173931 100644 --- a/spline/plugins/users/__init__.py +++ b/spline/plugins/users/__init__.py @@ -14,6 +14,7 @@ def add_routes_hook(map, *args, **kwargs): """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 diff --git a/spline/plugins/users/controllers/accounts.py b/spline/plugins/users/controllers/accounts.py index 03c9392..ba2fa26 100644 --- a/spline/plugins/users/controllers/accounts.py +++ b/spline/plugins/users/controllers/accounts.py @@ -10,6 +10,7 @@ from routes import request_config 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__) @@ -76,4 +77,19 @@ class AccountsController(BaseController): 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) diff --git a/spline/plugins/users/templates/widgets/user_state.mako b/spline/plugins/users/templates/widgets/user_state.mako index d279dc4..dbc73a0 100644 --- a/spline/plugins/users/templates/widgets/user_state.mako +++ b/spline/plugins/users/templates/widgets/user_state.mako @@ -1,9 +1,12 @@ -${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: + +${h.end_form()} +% else: +${h.form(url(controller='accounts', action='login_begin'), id='user')} - % endif ${h.end_form()} +% endif