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