From 6473ca8ef06d79666a9deb665f6a45cc606cdcf7 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 15 Feb 2011 15:59:55 +0100 Subject: [PATCH] appy.gen: implemented ToolMixin.performLogin (inspired from Plone authentication), minor bugfix while redirecting user to a page that must display a global status message; logged every translation deletion. --- gen/plone25/mixins/ToolMixin.py | 28 +++++++++++++++++++++- gen/plone25/mixins/__init__.py | 7 +++++- gen/plone25/wrappers/TranslationWrapper.py | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/gen/plone25/mixins/ToolMixin.py b/gen/plone25/mixins/ToolMixin.py index 5fea44c..cb91915 100644 --- a/gen/plone25/mixins/ToolMixin.py +++ b/gen/plone25/mixins/ToolMixin.py @@ -868,7 +868,33 @@ class ToolMixin(BaseMixin): '''Gets the translated month name of month numbered p_monthNumber.''' return self.translate(self.monthsIds[int(monthNumber)], domain='plone') - def logout(self): + def performLogin(self): + '''Logs the user in.''' + rq = self.REQUEST + jsEnabled = rq.get('js_enabled', False) in ('1', 1) + cookiesEnabled = rq.get('cookies_enabled', False) in ('1', 1) + urlBack = rq['HTTP_REFERER'] + + if jsEnabled and not cookiesEnabled: + msg = self.translate(u'You must enable cookies before you can ' \ + 'log in.', domain='plone') + return self.goto(urlBack, msg.encode('utf-8')) + + # Perform the Zope-level authentication + self.acl_users.credentials_cookie_auth.login() + login = rq['login_name'] + if self.portal_membership.isAnonymousUser(): + rq.RESPONSE.expireCookie('__ac', path='/') + msg = self.translate(u'Login failed', domain='plone') + logMsg = 'Authentication failed (tried with login "%s")' % login + else: + msg = self.translate(u'Welcome! You are now logged in.', + domain='plone') + logMsg = 'User "%s" has been logged in.' % login + self.log(logMsg) + return self.goto(rq['HTTP_REFERER'], msg.encode('utf-8')) + + def performLogout(self): '''Logs out the current user when he clicks on "disconnect".''' rq = self.REQUEST userId = self.portal_membership.getAuthenticatedMember().getId() diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index 1064e63..e4daf06 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -358,7 +358,12 @@ class BaseMixin: def goto(self, url, msg=None): '''Brings the user to some p_url after an action has been executed.''' if msg: - url += '?' + urllib.urlencode([('portal_status_message',msg)]) + # Remove previous message if any + if 'portal_status_message=' in url: + url = url[:url.find('portal_status_message=')-1] + if '?' in url: op = '&' + else: op = '?' + url += op + urllib.urlencode([('portal_status_message',msg)]) return self.REQUEST.RESPONSE.redirect(url) def showField(self, name, layoutType='view'): diff --git a/gen/plone25/wrappers/TranslationWrapper.py b/gen/plone25/wrappers/TranslationWrapper.py index fdc5792..a95f0e5 100644 --- a/gen/plone25/wrappers/TranslationWrapper.py +++ b/gen/plone25/wrappers/TranslationWrapper.py @@ -72,5 +72,6 @@ class TranslationWrapper(AbstractWrapper): def onDelete(self): # Call a custom "onDelete" if any. + self.log('Translation "%s" deleted by "%s".' % (self.id, self.user.id)) return self._callCustom('onDelete') # ------------------------------------------------------------------------------