[Checkins] SVN: Products.CMF Logout view added and PythonScript changed to use CookieCrumbler.
Charlie Clark
charlie at begeistert.org
Sat Apr 24 14:29:09 EDT 2010
Log message for revision 111384:
Logout view added and PythonScript changed to use CookieCrumbler.
Changed:
U Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py
U Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py
U Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/tests/test_CookieCrumbler.py
U Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py
U Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/configure.zcml
U Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/skins/zpt_control/logout.py
-=-
Modified: Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py
===================================================================
--- Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py 2010-04-24 17:57:57 UTC (rev 111383)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py 2010-04-24 18:29:09 UTC (rev 111384)
@@ -283,25 +283,13 @@
method( resp, self.auth_cookie, quote( ac ) )
security.declarePublic('logout')
- def logout(self):
- '''
- Logs out the user and redirects to the logout page.
- '''
- # XXX: this method violates the rules for tools/utilities:
- # it depends on self.REQUEST
- req = self.REQUEST
- resp = req['RESPONSE']
- method = self.getCookieMethod( 'expireAuthCookie'
- , self.defaultExpireAuthCookie )
- method( resp, cookie_name=self.auth_cookie )
- if self.logout_page:
- page = self.restrictedTraverse(self.logout_page, None)
- if page is not None:
- resp.redirect('%s?disable_cookie_login__=1'
- % page.absolute_url())
- return ''
- # We should not normally get here.
- return 'Logged out.'
+ def logout(self, response=None):
+ """
+ Logs out the user
+ """
+ if response is None:
+ req = self.REQUEST['RESPONSE']
+ self.defaultExpireAuthCookie(response, cookie_name=self.auth_cookie)
security.declarePublic('propertyLabel')
def propertyLabel(self, id):
Modified: Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py
===================================================================
--- Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py 2010-04-24 17:57:57 UTC (rev 111383)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py 2010-04-24 18:29:09 UTC (rev 111384)
@@ -59,4 +59,7 @@
def propertyLabel(id):
"""Return a label for the given property id
- """
\ No newline at end of file
+ """
+
+ def logout(response):
+ """Log the user out"""
Modified: Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/tests/test_CookieCrumbler.py
===================================================================
--- Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/tests/test_CookieCrumbler.py 2010-04-24 17:57:57 UTC (rev 111383)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/tests/test_CookieCrumbler.py 2010-04-24 18:29:09 UTC (rev 111384)
@@ -368,26 +368,6 @@
bt_removed = getattr(container, '__before_traverse__')
self.assertEqual(len(bt_removed.items()), 0)
- # def test_url_from_script(self):
- # """Check the right URL to redirect to is returned"""
- # from zope.component import getSiteManager, getUtility
- # from Products.CMFCore.tests.base.dummy import \
- # DummySite, DummyTool, DummyObject
- # root, cc, req, credentials = self._makeSite()
- # root = DummySite("Dummy Portal")
- # from Products.CMFCore.URLTool import URLTool
- # from Products.CMFCore.interfaces import IURLTool
- # sm = getSiteManager()
- # utool = URLTool()
- # sm.registerUtility(utool, IURLTool)
- # root._setObject('portal_url', utool)
- # from Products.CMFCore import utils
- # utool = utils.getToolByName(cc, 'portal_url')
- # login = root._getOb('login_form')
- # # print login.absolute_url()
- # self.assertEqual(login.absolute_url(),
- # cc.view_or_script('login_form'))
-
def test_suite():
return unittest.TestSuite((
Modified: Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py
===================================================================
--- Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py 2010-04-24 17:57:57 UTC (rev 111383)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py 2010-04-24 18:29:09 UTC (rev 111384)
@@ -37,6 +37,7 @@
from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.formlib.form import EditFormBase
from Products.CMFDefault.utils import Message as _
+from Products.CMFDefault.browser.utils import ViewBase, memoize
class UnauthorizedView(BrowserView):
@@ -228,3 +229,31 @@
rtool.mailPassword(data['name'], self.request)
self.status = _(u'Your password has been mailed to you.')
return self._setRedirect('portal_actions', 'user/login')
+
+
+class Logout(ViewBase):
+ """Log the user out"""
+
+ @memoize
+ def logged_in(self):
+ """Check whether the user is (still logged in)"""
+ mtool = self._getTool('portal_membership')
+ return mtool.isAnonymousUser()
+
+ @memoize
+ def logout(self):
+ """Log the user out"""
+ cctool = self._getTool('cookie_authentication')
+ cctool.logout(self.request.response)
+
+ @memoize
+ def clear_skin_cookie(self):
+ """Remove skin cookie"""
+ stool = self._getTool('portal_skins')
+ stool.clearSkinCookie()
+
+ def __call__(self):
+ """Clear cookies and return the template"""
+ self.clear_skin_cookie()
+ self.logout()
+ return super(Logout, self).__call__()
Modified: Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/configure.zcml
===================================================================
--- Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/configure.zcml 2010-04-24 17:57:57 UTC (rev 111383)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/configure.zcml 2010-04-24 18:29:09 UTC (rev 111384)
@@ -176,6 +176,15 @@
class=".authentication.LoginFormView"
permission="zope2.View"
/>
+
+ <browser:page
+ for="Products.CMFCore.interfaces.ISiteRoot"
+ layer="..interfaces.ICMFDefaultSkin"
+ name="logout.html"
+ class=".authentication.Logout"
+ template="templates/logged_out.pt"
+ permission="zope2.View"
+ />
<browser:page
for="Products.CMFCore.interfaces.ISiteRoot"
Modified: Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/skins/zpt_control/logout.py
===================================================================
--- Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/skins/zpt_control/logout.py 2010-04-24 17:57:57 UTC (rev 111383)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/skins/zpt_control/logout.py 2010-04-24 18:29:09 UTC (rev 111384)
@@ -1,8 +1,13 @@
## Script (Python) "logout"
##title=Logout handler
##parameters=
+from Products.CMFCore.utils import getToolByName
+
+cctool = getToolByName(context, 'cookie_authentication')
+stool = getToolByName(context, 'portal_skins')
+utool = getToolByName(context, 'portal_url')
REQUEST = context.REQUEST
-if REQUEST.has_key('portal_skin'):
- context.portal_skins.clearSkinCookie()
-REQUEST.RESPONSE.expireCookie('__ac', path='/')
-return REQUEST.RESPONSE.redirect(REQUEST.URL1+'/logged_out')
+
+stool.clearSkinCookie()
+cctool.logout(REQUEST.RESPONSE)
+return REQUEST.RESPONSE.redirect(utool() + '/logged_out')
\ No newline at end of file
More information about the checkins
mailing list