style.
[Plinn.git] / skins / custom_generic / logged_in.py
1 ##parameters=
2 ##
3 from Products.CMFCore.utils import getUtilityByInterfaceName
4 from Products.CMFCore.utils import getToolByName
5 from Products.CMFDefault.utils import decode
6 from ZTUtils import make_query as mq
7 from Products.CMFDefault.utils import Message as _
8
9 mtool = getToolByName(script, 'portal_membership')
10 ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
11 stool = getToolByName(script, 'portal_skins')
12 utool = getToolByName(script, 'portal_url')
13 atool = getToolByName(script, 'portal_actions')
14 portal_url = utool()
15 portal = utool.getPortalObject()
16
17
18 if stool.updateSkinCookie():
19 context.setupCurrentSkin()
20
21
22 options = {}
23
24 isAnon = mtool.isAnonymousUser()
25 if isAnon:
26 context.REQUEST.RESPONSE.expireCookie('__ac', path='/')
27 options['is_anon'] = True
28 options['title'] = _(u'Login failure')
29 options['admin_email'] = ptool.getProperty('email_from_address')
30 else:
31 mtool.createMemberArea()
32 member = mtool.getAuthenticatedMember()
33 now = context.ZopeTime()
34 last_login = member.getProperty('login_time', None)
35 member.setProperties(last_login_time=last_login, login_time=now)
36 is_first_login = (last_login == '2000/01/01' and
37 ptool.getProperty('validate_email'))
38 if is_first_login:
39 member.setProperties(last_login_time='1999/01/01', login_time=now)
40 target = '%s/password_form' % portal_url
41 context.REQUEST.RESPONSE.redirect(target)
42 return
43 else:
44 member.setProperties(last_login_time=last_login, login_time=now)
45 came_from = context.REQUEST.get('came_from', None)
46 if came_from:
47 return context.REQUEST.RESPONSE.redirect(came_from)
48 else :
49 url = atool.getActionInfo('user/logged_in', object=portal)['url']
50 url = '%s?%s' %(url, mq(portal_status_message=_('Login success')))
51 return context.REQUEST.RESPONSE.redirect(url)
52
53 return context.logged_in_template(**decode(options, script))