1 | ## Script (Python) "logged_in" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=came_from=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | """Prepare user login |
---|
11 | modified from cps_default/logged_in.py |
---|
12 | |
---|
13 | $Id: logged_in.py 34693 2006-03-23 17:44:22Z ogrisel $ |
---|
14 | """ |
---|
15 | |
---|
16 | from urllib import unquote |
---|
17 | |
---|
18 | def checkRedirect(portal, mtool): |
---|
19 | to_member_home = False |
---|
20 | to_workspaces = False |
---|
21 | has_home = mtool.getHomeFolder() |
---|
22 | if has_home: |
---|
23 | to_member_home = True |
---|
24 | if not has_home and mtool.checkPermission('View', portal.workspaces): |
---|
25 | to_workspaces = True |
---|
26 | return to_member_home, to_workspaces |
---|
27 | |
---|
28 | utool = context.portal_url |
---|
29 | mtool = context.portal_membership |
---|
30 | portal = utool.getPortalObject() |
---|
31 | portal_absolute_url = portal.absolute_url() |
---|
32 | |
---|
33 | redirect_url = came_from |
---|
34 | redirect_to_portal = False |
---|
35 | to_member_home = False |
---|
36 | to_workspaces = False |
---|
37 | to_waeup_student_home = False |
---|
38 | |
---|
39 | is_anon = mtool.isAnonymousUser() |
---|
40 | member = mtool.getAuthenticatedMember() |
---|
41 | |
---|
42 | if not redirect_url or redirect_url.endswith('/logged_out'): |
---|
43 | if not is_anon: |
---|
44 | if "Student" in member.getRoles(): |
---|
45 | member_id = str(member) |
---|
46 | student = getattr(context.campus.students,member_id,) |
---|
47 | if context.portal_workflow.getInfoFor(student, |
---|
48 | 'review_state', |
---|
49 | None) == "created": |
---|
50 | student.content_status_modify(workflow_action="enter_application_pin") |
---|
51 | da = {} |
---|
52 | pin = request.get('pin') |
---|
53 | da['app_ac_pin'] = pin |
---|
54 | da['app_ac_date'] = current |
---|
55 | application.getContent().edit(mapping = da) |
---|
56 | to_waeup_student_home = True |
---|
57 | elif "Manager" in member.getRoles(): |
---|
58 | pass |
---|
59 | else: |
---|
60 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
61 | if (not to_member_home) and (not to_workspaces): |
---|
62 | redirect_to_portal = True |
---|
63 | else: |
---|
64 | redirect_url = unquote(redirect_url) |
---|
65 | # One can be redirected from an http page while the login is done from an |
---|
66 | # https page. This is a fix for #1205. |
---|
67 | # A better option here would be to replace the previous portal_absolute_url |
---|
68 | # prefix in the redirect_url by the current portal absolute URL. |
---|
69 | if not redirect_url.startswith(portal_absolute_url): |
---|
70 | if not is_anon: |
---|
71 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
72 | if (not to_member_home) and (not to_workspaces): |
---|
73 | redirect_to_portal = True |
---|
74 | |
---|
75 | if to_waeup_student_home: |
---|
76 | member.setProperties(last_login_time=current,login_time=current) |
---|
77 | return response.redirect("%s" % student.absolute_url()) |
---|
78 | |
---|
79 | elif to_member_home: |
---|
80 | redirect_url = mtool.getHomeFolder().absolute_url() |
---|
81 | elif to_workspaces: |
---|
82 | redirect_url = portal.workspaces.absolute_url() |
---|
83 | elif redirect_to_portal: |
---|
84 | redirect_url = portal_absolute_url |
---|
85 | |
---|
86 | REQUEST = context.REQUEST |
---|
87 | RESPONSE = REQUEST.RESPONSE |
---|
88 | |
---|
89 | # Setup skins |
---|
90 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
91 | utool.updateSkinCookie()): |
---|
92 | context.setupCurrentSkin() |
---|
93 | |
---|
94 | # Anonymous |
---|
95 | if is_anon: |
---|
96 | RESPONSE.expireCookie('__ac', path='/') |
---|
97 | return context.user_logged_in_failed() |
---|
98 | |
---|
99 | login_time = member.getProperty('login_time', '2000/01/01') |
---|
100 | first_time = (str(login_time) == '2000/01/01') |
---|
101 | |
---|
102 | if first_time and member.has_role('Member'): |
---|
103 | mtool.createMemberArea() |
---|
104 | now = context.ZopeTime() |
---|
105 | member.setProperties(last_login_time=now, login_time=now) |
---|
106 | |
---|
107 | if to_member_home or to_workspaces: |
---|
108 | redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in') |
---|
109 | RESPONSE.redirect(redirect_url) |
---|