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.

This commit is contained in:
Gaetan Delannay 2011-02-15 15:59:55 +01:00
parent 91c657238d
commit 6473ca8ef0
3 changed files with 34 additions and 2 deletions

View file

@ -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()

View file

@ -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'):

View file

@ -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')
# ------------------------------------------------------------------------------