root/CPS3/products/CPSDefault/trunk/skins/cps_default/logged_in.py

Revision 52708, 2.5 kB (checked in by madarche, 1 year ago)

Made the check for the need to create a member area happen at every login into
the portal, not only at the first login of a user. This is because the
homeless property of a user can be modified after the first login of the user
into the portal.

Note that this change does not really modify the current situation since the
"last_login_time" property is never saved at this time, which seems to be a bug
by the way.

  • Property svn:keywords set to Id
Line 
1 ##parameters=came_from=None
2 """Prepare user login
3
4 $Id$
5 """
6
7 from urllib import unquote
8
9 def checkRedirect(portal, mtool):
10     to_member_home = False
11     to_workspaces = False
12     has_home = mtool.getHomeFolder()
13     if has_home:
14         to_member_home = True
15     if not has_home and mtool.checkPermission('View', portal.workspaces):
16         to_workspaces = True
17     return to_member_home, to_workspaces
18
19 utool = context.portal_url
20 mtool = context.portal_membership
21 portal = utool.getPortalObject()
22 portal_absolute_url = portal.absolute_url()
23
24 redirect_url = came_from
25 redirect_to_portal = False
26 to_member_home = False
27 to_workspaces = False
28
29 is_anon = mtool.isAnonymousUser()
30 member = mtool.getAuthenticatedMember()
31
32 if not redirect_url or redirect_url.endswith('/logged_out'):
33     if not is_anon:
34         to_member_home, to_workspaces = checkRedirect(portal, mtool)
35     if (not to_member_home) and (not to_workspaces):
36         redirect_to_portal = True
37 else:
38     redirect_url = unquote(redirect_url)
39     # One can be redirected from an http page while the login is done from an
40     # https page. This is a fix for #1205.
41     # A better option here would be to replace the previous portal_absolute_url
42     # prefix in the redirect_url by the current portal absolute URL.
43     if not redirect_url.startswith(portal_absolute_url):
44         if not is_anon:
45             to_member_home, to_workspaces = checkRedirect(portal, mtool)
46         if (not to_member_home) and (not to_workspaces):
47             redirect_to_portal = True
48
49 if to_member_home:
50     redirect_url = mtool.getHomeFolder().absolute_url()
51 elif to_workspaces:
52     redirect_url = portal.workspaces.absolute_url()
53 elif redirect_to_portal:
54     redirect_url = portal_absolute_url
55
56 REQUEST = context.REQUEST
57 RESPONSE = REQUEST.RESPONSE
58
59 # Setup skins
60 if (getattr(utool, 'updateSkinCookie', False) and
61     utool.updateSkinCookie()):
62     context.setupCurrentSkin()
63
64 # Anonymous
65 if is_anon:
66     RESPONSE.expireCookie('__ac', path='/')
67     return context.user_logged_in_failed()
68
69 login_time = member.getProperty('last_login_time', None)
70
71 # We don't want to create a member area for the Zope admin,
72 # nor can we setProperties on it.
73 if member.has_role('Member'):
74     # This create the member area only if needed
75     mtool.createMemberArea()
76     now = context.ZopeTime()
77     member.setProperties(login_time=now, last_login_time=login_time)
78
79 if to_member_home or to_workspaces:
80     redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in')
81 RESPONSE.redirect(redirect_url)
Note: See TracBrowser for help on using the browser.