[Checkins] SVN: Products.CMF Signature for credentialsChanged updated to cope without being passed the request.

Charlie Clark charlie at begeistert.org
Tue Apr 27 14:18:03 EDT 2010


Log message for revision 111509:
  Signature for credentialsChanged updated to cope without being passed the request.
  
  logout will now return the logout view for logging out from the ZMI
  
  doctest added for logging out & skin script updated to work 

Changed:
  U   Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py
  U   Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py
  U   Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py
  U   Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py
  U   Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/tests/authentication.txt
  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-27 17:57:25 UTC (rev 111508)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py	2010-04-27 18:18:02 UTC (rev 111509)
@@ -34,7 +34,7 @@
 from ZPublisher.HTTPRequest import HTTPRequest
 
 from Products.CMFCore.interfaces import ICookieCrumbler
-from Products.CMFCore.utils import UniqueObject
+from Products.CMFCore.utils import UniqueObject, getToolByName
 
 
 # Constants.
@@ -263,7 +263,7 @@
             req._logout_path = phys_path + ('logout',)
 
     security.declarePublic('credentialsChanged')
-    def credentialsChanged(self, user, name, pw, request):
+    def credentialsChanged(self, user, name, pw, request=None):
         """
         Updates cookie credentials if user details are changed.
         """
@@ -280,9 +280,17 @@
         """
         Logs out the user
         """
+        target = None
         if response is None:
             response = self.REQUEST['RESPONSE'] # BBB for App.Management
-        self.defaultExpireAuthCookie(response, cookie_name=self.auth_cookie)
+            atool = getToolByName(self, 'portal_actions')
+            target = atool.getActionInfo('user/logout')['url']
+        method = self.getCookieMethod('expireAuthCookie',
+                                       self.defaultExpireAuthCookie)
+        method(response, cookie_name=self.auth_cookie)
+        # BBB for App.Management
+        if target is not None:
+            response.redirect(target)
 
     security.declarePublic('propertyLabel')
     def propertyLabel(self, id):

Modified: Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py
===================================================================
--- Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py	2010-04-27 17:57:25 UTC (rev 111508)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py	2010-04-27 18:18:02 UTC (rev 111509)
@@ -335,8 +335,8 @@
             name = user.getUserName()
             # this really does need to be the user name, and not the user id,
             # because we're dealing with authentication credentials
-            cctool = getToolByName(self, 'cookie_authentication')
             try:
+                cctool = getToolByName(self, 'cookie_authentication')
                 cctool.credentialsChanged(user, name, password, REQUEST)
             except AttributeError:
                 # No CookieCrumbler

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-27 17:57:25 UTC (rev 111508)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py	2010-04-27 18:18:02 UTC (rev 111509)
@@ -28,6 +28,10 @@
         the parent URL if local_cookie_path is True otherwise /"""
         return path
 
+    def getCookieMethod(name, default):
+        """Get the cookie handler.
+        The cookie handler maybe overridden by acquisition."""
+
     def defaultSetAuthCookie(resp, cookie_name, cookie_value):
         """Set the authorisation cookie"""
 
@@ -61,4 +65,6 @@
         """
         
     def logout(response):
-        """Log the user out"""
+        """
+        Deprecated
+        Log the user out"""

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-27 17:57:25 UTC (rev 111508)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py	2010-04-27 18:18:02 UTC (rev 111509)
@@ -46,9 +46,9 @@
         cctool = getToolByName(view, 'cookie_authentication')
         method = cctool.getCookieMethod('expireAuthCookie',
                                         cctool.defaultExpireAuthCookie)
-        method(view.response, cctool.auth_cookie)
+        method(view.request.response, cctool.auth_cookie)
     except AttributeError:
-        view.response.expireCookie('__ac', path='/')
+        view.request.response.expireCookie('__ac', path='/')
 
 
 class UnauthorizedView(BrowserView):
@@ -268,7 +268,7 @@
         """Log the user out"""
         _expireAuthCookie(self)
     
-    @memoize    
+    @memoize
     def clear_skin_cookie(self):
         """Remove skin cookie"""
         stool = self._getTool('portal_skins')
@@ -276,6 +276,8 @@
     
     def __call__(self):
         """Clear cookies and return the template"""
-        self.clear_skin_cookie()
-        self.logout()
+        if not self.logged_in():
+            self.clear_skin_cookie()
+            self.logout()
+            return self.request.response.redirect(self.request.URL)
         return super(Logout, self).__call__()

Modified: Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/tests/authentication.txt
===================================================================
--- Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/tests/authentication.txt	2010-04-27 17:57:25 UTC (rev 111508)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/tests/authentication.txt	2010-04-27 18:18:02 UTC (rev 111509)
@@ -120,3 +120,14 @@
     True
     >>> '[[zope][Constraint not satisfied]]' in browser.contents
     True
+
+Log the user in and then out
+    >>> browser.open('http://localhost/site/@@login.html')
+    >>> browser.getControl('[[cmf_default][Member ID]]').value = 'mbr'
+    >>> browser.getControl('[[cmf_default][Password]]').value = 'mbrpw'
+    >>> browser.getControl('[[cmf_default][Login]]').click()
+    >>> '[[cmf_default][Login success]]' in browser.contents
+    True
+    >>> browser.open('http://localhost/site/@@logout.html')
+    >>> '[cmf_default][You have been logged out.' in browser.contents
+    True
\ No newline at end of file

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-27 17:57:25 UTC (rev 111508)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/skins/zpt_control/logout.py	2010-04-27 18:18:02 UTC (rev 111509)
@@ -3,11 +3,15 @@
 ##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
 
 stool.clearSkinCookie()
-cctool.logout(REQUEST.RESPONSE)
+try:
+    cctool = getToolByName(context, 'cookie_authentication')
+    cctool.logout(REQUEST.RESPONSE)
+except AttributeError:
+    expireCookie('__ac', path='/')
+
 return REQUEST.RESPONSE.redirect(utool() + '/logged_out')
\ No newline at end of file



More information about the checkins mailing list