[Checkins] SVN: Products.CMF Hook for MembershipTool updated to call the cookie_authentication tool directly rather than depend upon a request attribute.
Charlie Clark
charlie at begeistert.org
Tue Apr 27 10:19:37 EDT 2010
Log message for revision 111483:
Hook for MembershipTool updated to call the cookie_authentication tool directly rather than depend upon a request attribute.
Cookie expiration for views only needs the view as a parameter as a view must have request.reponse.
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
-=-
Modified: Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py
===================================================================
--- Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py 2010-04-27 13:32:03 UTC (rev 111482)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/CookieCrumbler.py 2010-04-27 14:19:36 UTC (rev 111483)
@@ -261,18 +261,19 @@
# Cookies are in use.
# Provide a logout page.
req._logout_path = phys_path + ('logout',)
- req._credentials_changed_path = (
- phys_path + ('credentialsChanged',))
security.declarePublic('credentialsChanged')
- def credentialsChanged(self, user, name, pw):
- # XXX: this method violates the rules for tools/utilities:
- # it depends on self.REQUEST
+ def credentialsChanged(self, user, name, pw, request):
+ """
+ Updates cookie credentials if user details are changed.
+ """
+ if request is None:
+ request = self.REQUEST # BBB for Membershiptool
+ reponse = request['RESPONSE']
ac = encodestring('%s:%s' % (name, pw)).rstrip()
- method = self.getCookieMethod( 'setAuthCookie'
- , self.defaultSetAuthCookie )
- resp = self.REQUEST['RESPONSE']
- method( resp, self.auth_cookie, quote( ac ) )
+ method = self.getCookieMethod('setAuthCookie',
+ self.defaultSetAuthCookie)
+ method(reponse, self.auth_cookie, quote(ac))
security.declarePublic('logout')
def logout(self, response=None):
@@ -280,7 +281,7 @@
Logs out the user
"""
if response is None:
- req = self.REQUEST['RESPONSE']
+ response = self.REQUEST['RESPONSE'] # BBB for App.Management
self.defaultExpireAuthCookie(response, cookie_name=self.auth_cookie)
security.declarePublic('propertyLabel')
Modified: Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py
===================================================================
--- Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py 2010-04-27 13:32:03 UTC (rev 111482)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/MembershipTool.py 2010-04-27 14:19:36 UTC (rev 111483)
@@ -335,11 +335,12 @@
name = user.getUserName()
# this really does need to be the user name, and not the user id,
# because we're dealing with authentication credentials
- p = getattr(REQUEST, '_credentials_changed_path', None)
- if p is not None:
- # Use an interface provided by CookieCrumbler.
- change = self.restrictedTraverse(p)
- change(user, name, password)
+ cctool = getToolByName(self, 'cookie_authentication')
+ try:
+ cctool.credentialsChanged(user, name, password, REQUEST)
+ except AttributeError:
+ # No CookieCrumbler
+ pass
security.declareProtected(ManageUsers, 'getMemberById')
def getMemberById(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-27 13:32:03 UTC (rev 111482)
+++ Products.CMFCore/branches/cookiecrumbler_with_views/Products/CMFCore/interfaces/_cookieCrumbler.py 2010-04-27 14:19:36 UTC (rev 111483)
@@ -51,11 +51,10 @@
def __call__(container, req):
"""The __before_publishing_traverse__ hook."""
- def credentialsChanged(user, name, pw):
+ def credentialsChanged(user, name, pw, request):
"""
- Deprecated
- # XXX: this method violates the rules for tools/utilities:
- # it depends on self.REQUEST """
+ Updates cookie credentials if user details are changed.
+ """
def propertyLabel(id):
"""Return a label for the given property id
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 13:32:03 UTC (rev 111482)
+++ Products.CMFDefault/branches/cookiecrumbler_with_views/Products/CMFDefault/browser/authentication.py 2010-04-27 14:19:36 UTC (rev 111483)
@@ -41,14 +41,14 @@
from Products.CMFDefault.browser.utils import ViewBase, memoize
-def _expireAuthCookie(view, response):
+def _expireAuthCookie(view):
try:
cctool = getToolByName(view, 'cookie_authentication')
method = cctool.getCookieMethod('expireAuthCookie',
cctool.defaultExpireAuthCookie)
- method(response, cctool.auth_cookie)
+ method(view.response, cctool.auth_cookie)
except AttributeError:
- response.expireCookie('__ac', path='/')
+ view.response.expireCookie('__ac', path='/')
class UnauthorizedView(BrowserView):
@@ -81,7 +81,7 @@
self.context = self.__parent__
raise Forbidden(self.forbidden_template())
- _expireAuthCookie(self, req.response)
+ _expireAuthCookie(self)
came_from = req.get('came_from', None)
if came_from is None:
came_from = req.get('ACTUAL_URL')
@@ -197,7 +197,7 @@
def handle_login_validate(self, action, data):
mtool = self._getTool('portal_membership')
if mtool.isAnonymousUser():
- _expireAuthCookie(self, self.request.response)
+ _expireAuthCookie(self)
return (_(u'Login failure'),)
return None
@@ -266,8 +266,7 @@
@memoize
def logout(self):
"""Log the user out"""
- cctool = self._getTool('cookie_authentication')
- cctool.logout(self.request.response)
+ _expireAuthCookie(self)
@memoize
def clear_skin_cookie(self):
More information about the checkins
mailing list