[CMF-checkins] CVS: CMF - CookieCrumbler.py:1.3

tseaver@digicool.com tseaver@digicool.com
Wed, 11 Apr 2001 17:01:10 -0400 (EDT)


Update of /cvs-repository/CMF/CMFCore
In directory korak:/tmp/cvs-serv30252/CMFCore

Modified Files:
	CookieCrumbler.py 
Log Message:


 - Added hooks to CookieCrumbler to permit site managers to customize
   seting/expiring of the authentication cookie by adding PythonScripts;
   two default filesystem implementations are in CMFDefault's "control"
   skin.




--- Updated File CookieCrumbler.py in package CMF --
--- CookieCrumbler.py	2001/04/08 19:18:09	1.2
+++ CookieCrumbler.py	2001/04/11 21:01:09	1.3
@@ -148,9 +148,18 @@
         try: del req.environ[name]
         except: pass
 
-    security.declarePrivate('setAuthCookie')
-    def setAuthCookie(self, resp, ac):
-        resp.setCookie(self.auth_cookie, quote(ac), path='/')
+    # Allow overridable cookie set/expiration methods.
+    security.declarePrivate('getCookieMethod')
+    def getCookieMethod( self, name='setAuthCookie', default=None ):
+        return getattr( self.aq_inner.aq_parent, name, default )
+
+    security.declarePrivate('setDefaultAuthCookie')
+    def defaultSetAuthCookie( self, resp, cookie_name, cookie_value ):
+        resp.setCookie( cookie_name, cookie_value, path='/')
+
+    security.declarePrivate('defaultExpireAuthCookie')
+    def defaultExpireAuthCookie( self, cookie_name ):
+        resp.expireCookie( cookie_name, path='/')
 
     security.declarePrivate('modifyRequest')
     def modifyRequest(self, req, resp):
@@ -172,7 +181,9 @@
                 else:
                     # Expire the user name
                     resp.expireCookie(self.name_cookie, path='/')
-                self.setAuthCookie(resp, ac)
+                method = self.getCookieMethod( 'setAuthCookie'
+                                             , self.defaultSetAuthCookie )
+                method( resp, self.auth_cookie, quote( ac ) )
                 self.delRequestVar(req, self.name_cookie)
                 self.delRequestVar(req, self.pw_cookie)
                 return ATTEMPT_LOGIN
@@ -269,7 +280,9 @@
         '''
         req = self.REQUEST
         resp = req['RESPONSE']
-        resp.expireCookie(self.auth_cookie, path='/')
+        method = self.getCookieMethod( 'expireAuthCookie'
+                                     , self.defaultExpireAuthCookie )
+        method( cookie_name=self.auth_cookie )
         redir = 0
         if self.logout_page:
             iself = getattr(self, 'aq_inner', self)