Back to index

plone3  3.1.7
logged_in.py
Go to the documentation of this file.
00001 ##parameters=
00002 ##
00003 from Products.CMFCore.utils import getUtilityByInterfaceName
00004 from Products.CMFCore.utils import getToolByName
00005 from Products.CMFDefault.utils import decode
00006 from Products.CMFDefault.utils import Message as _
00007 
00008 mtool = getToolByName(script, 'portal_membership')
00009 ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
00010 stool = getToolByName(script, 'portal_skins')
00011 utool = getToolByName(script, 'portal_url')
00012 portal_url = utool()
00013 
00014 
00015 if stool.updateSkinCookie():
00016     context.setupCurrentSkin()
00017 
00018 
00019 options = {}
00020 
00021 isAnon = mtool.isAnonymousUser()
00022 if isAnon:
00023     context.REQUEST.RESPONSE.expireCookie('__ac', path='/')
00024     options['is_anon'] = True
00025     options['title'] = _(u'Login failure')
00026     options['admin_email'] = ptool.getProperty('email_from_address')
00027 else:
00028     mtool.createMemberArea()
00029     member = mtool.getAuthenticatedMember()
00030     now = context.ZopeTime()
00031     last_login = member.getProperty('login_time', None)
00032     member.setProperties(last_login_time=last_login, login_time=now)
00033     is_first_login = (last_login == '2000/01/01' and
00034                       ptool.getProperty('validate_email'))
00035     if is_first_login:
00036         member.setProperties(last_login_time='1999/01/01', login_time=now)
00037         target = '%s/password_form' % portal_url
00038         context.REQUEST.RESPONSE.redirect(target)
00039         return
00040     else:
00041         member.setProperties(last_login_time=last_login, login_time=now)
00042         came_from = context.REQUEST.get('came_from', None)
00043         if came_from:
00044             context.REQUEST.RESPONSE.redirect(came_from)
00045             return
00046         options['is_anon'] = False
00047         options['title'] = _(u'Login success')
00048 
00049 return context.logged_in_template(**decode(options, script))