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 | import DateTime |
---|
16 | current = DateTime.DateTime() |
---|
17 | |
---|
18 | from urllib import unquote |
---|
19 | |
---|
20 | def checkRedirect(portal, mtool): |
---|
21 | to_member_home = False |
---|
22 | to_workspaces = False |
---|
23 | has_home = mtool.getHomeFolder() |
---|
24 | if has_home: |
---|
25 | to_member_home = True |
---|
26 | if not has_home and mtool.checkPermission('View', portal.workspaces): |
---|
27 | to_workspaces = True |
---|
28 | return to_member_home, to_workspaces |
---|
29 | |
---|
30 | request = context.REQUEST |
---|
31 | response = request.RESPONSE |
---|
32 | utool = context.portal_url |
---|
33 | mtool = context.portal_membership |
---|
34 | wftool = context.portal_workflow |
---|
35 | portal = utool.getPortalObject() |
---|
36 | portal_absolute_url = portal.absolute_url() |
---|
37 | |
---|
38 | redirect_url = came_from |
---|
39 | redirect_to_portal = False |
---|
40 | to_member_home = False |
---|
41 | to_workspaces = False |
---|
42 | to_waeup_student_home = False |
---|
43 | |
---|
44 | is_anon = mtool.isAnonymousUser() |
---|
45 | member = mtool.getAuthenticatedMember() |
---|
46 | |
---|
47 | if not redirect_url or redirect_url.endswith('/logged_out'): |
---|
48 | if not is_anon: |
---|
49 | if "Student" in member.getRoles(): |
---|
50 | to_waeup_student_home = True |
---|
51 | info = context.getStudentInfo() |
---|
52 | student = info['student'] |
---|
53 | ## member_id = str(member) |
---|
54 | ## student = getattr(context.campus.students,member_id,) |
---|
55 | ## if context.portal_workflow.getInfoFor(student, |
---|
56 | ## 'review_state', |
---|
57 | ## None) == "created": |
---|
58 | if info['review_state'] == "created": |
---|
59 | student.content_status_modify(workflow_action="enter_application_pin") |
---|
60 | da = {} |
---|
61 | pin = request.get('pin') |
---|
62 | da['app_ac_pin'] = pin |
---|
63 | da['app_ac_date'] = current |
---|
64 | info['app_doc'].edit(mapping = da) |
---|
65 | elif "Manager" in member.getRoles(): |
---|
66 | pass |
---|
67 | else: |
---|
68 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
69 | if (not to_member_home) and (not to_workspaces): |
---|
70 | redirect_to_portal = True |
---|
71 | else: |
---|
72 | redirect_url = unquote(redirect_url) |
---|
73 | # One can be redirected from an http page while the login is done from an |
---|
74 | # https page. This is a fix for #1205. |
---|
75 | # A better option here would be to replace the previous portal_absolute_url |
---|
76 | # prefix in the redirect_url by the current portal absolute URL. |
---|
77 | if not redirect_url.startswith(portal_absolute_url): |
---|
78 | if not is_anon: |
---|
79 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
80 | if (not to_member_home) and (not to_workspaces): |
---|
81 | redirect_to_portal = True |
---|
82 | |
---|
83 | if to_waeup_student_home: |
---|
84 | member.setProperties(last_login_time=current,login_time=current) |
---|
85 | if info['review_state'] == "application_pin_entered": |
---|
86 | wftool.doActionFor(info['app'],'open',dest_container=info['app']) |
---|
87 | return response.redirect("%s/passport_entry_view" % student.absolute_url()) |
---|
88 | return response.redirect("%s" % student.absolute_url()) |
---|
89 | |
---|
90 | elif to_member_home: |
---|
91 | redirect_url = mtool.getHomeFolder().absolute_url() |
---|
92 | elif to_workspaces: |
---|
93 | redirect_url = portal.workspaces.absolute_url() |
---|
94 | elif redirect_to_portal: |
---|
95 | redirect_url = portal_absolute_url |
---|
96 | |
---|
97 | REQUEST = context.REQUEST |
---|
98 | RESPONSE = REQUEST.RESPONSE |
---|
99 | |
---|
100 | # Setup skins |
---|
101 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
102 | utool.updateSkinCookie()): |
---|
103 | context.setupCurrentSkin() |
---|
104 | |
---|
105 | # Anonymous |
---|
106 | if is_anon: |
---|
107 | RESPONSE.expireCookie('__ac', path='/') |
---|
108 | return context.user_logged_in_failed() |
---|
109 | |
---|
110 | login_time = member.getProperty('login_time', '2000/01/01') |
---|
111 | first_time = (str(login_time) == '2000/01/01') |
---|
112 | |
---|
113 | if first_time and member.has_role('Member'): |
---|
114 | mtool.createMemberArea() |
---|
115 | now = context.ZopeTime() |
---|
116 | member.setProperties(last_login_time=now, login_time=now) |
---|
117 | |
---|
118 | if to_member_home or to_workspaces: |
---|
119 | redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in') |
---|
120 | RESPONSE.redirect(redirect_url) |
---|