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 1018 2006-12-08 23:00:27Z henrik $ |
---|
14 | """ |
---|
15 | import DateTime |
---|
16 | current = DateTime.DateTime() |
---|
17 | import logging |
---|
18 | logger = logging.getLogger('Student.Login') |
---|
19 | |
---|
20 | |
---|
21 | from urllib import unquote |
---|
22 | |
---|
23 | def checkRedirect(portal, mtool): |
---|
24 | to_member_home = False |
---|
25 | to_workspaces = False |
---|
26 | ## has_home = mtool.getHomeFolder() |
---|
27 | ## if has_home: |
---|
28 | ## to_member_home = True |
---|
29 | ## if not has_home and mtool.checkPermission('View', portal.workspaces): |
---|
30 | ## to_workspaces = True |
---|
31 | return to_member_home, to_workspaces |
---|
32 | |
---|
33 | request = context.REQUEST |
---|
34 | response = request.RESPONSE |
---|
35 | utool = context.portal_url |
---|
36 | mtool = context.portal_membership |
---|
37 | wftool = context.portal_workflow |
---|
38 | portal = utool.getPortalObject() |
---|
39 | portal_absolute_url = portal.absolute_url() |
---|
40 | |
---|
41 | redirect_url = came_from |
---|
42 | redirect_to_portal = False |
---|
43 | to_member_home = False |
---|
44 | to_workspaces = False |
---|
45 | to_waeup_student_home = False |
---|
46 | |
---|
47 | is_anon = mtool.isAnonymousUser() |
---|
48 | member = mtool.getAuthenticatedMember() |
---|
49 | |
---|
50 | if redirect_url.endswith('/logged_out'): |
---|
51 | redirect_to_portal = True |
---|
52 | else: |
---|
53 | if not is_anon: |
---|
54 | if "Student" in member.getRoles(): |
---|
55 | to_waeup_student_home = True |
---|
56 | students = context.portal_url.getPortalObject().campus.students |
---|
57 | student = getattr(students,str(member)) |
---|
58 | student_app = getattr(student,'application') |
---|
59 | student_pume = getattr(student,'pume',None) |
---|
60 | s_review_state = wftool.getInfoFor(student,'review_state',None) |
---|
61 | a_review_state = wftool.getInfoFor(student_app,'review_state',None) |
---|
62 | logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state)) |
---|
63 | app_doc = student_app.getContent() |
---|
64 | #from Products.zdb import set_trace |
---|
65 | #set_trace() |
---|
66 | if s_review_state in ("student_created","admitted") and\ |
---|
67 | a_review_state == 'created' : |
---|
68 | wftool.doActionFor(student_app,'open') |
---|
69 | if student_pume is not None: |
---|
70 | wftool.doActionFor(student_pume,'close') |
---|
71 | da = {} |
---|
72 | pin = request.get('pin') |
---|
73 | if not pin: |
---|
74 | jamb_reg_no = app_doc.jamb_reg_no |
---|
75 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
76 | res = context.portal_pins(student=reg_no) |
---|
77 | if len(res) > 0: |
---|
78 | break |
---|
79 | if len(res) > 0: |
---|
80 | p = res[0].pin |
---|
81 | if len(p) > 10: |
---|
82 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
83 | else: |
---|
84 | pin = p |
---|
85 | da['app_ac_pin'] = pin |
---|
86 | da['app_ac_date'] = current |
---|
87 | app_doc.edit(mapping = da) |
---|
88 | elif s_review_state in ("admitted") and a_review_state == 'opened' and\ |
---|
89 | not app_doc.app_ac_pin: |
---|
90 | jamb_reg_no = app_doc.jamb_reg_no |
---|
91 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
92 | res = context.portal_pins(student=reg_no) |
---|
93 | if len(res) > 0: |
---|
94 | break |
---|
95 | if len(res) > 0: |
---|
96 | p = res[0].pin |
---|
97 | if len(p) > 10: |
---|
98 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
99 | else: |
---|
100 | pin = p |
---|
101 | da = {} |
---|
102 | da['app_ac_pin'] = pin |
---|
103 | app_doc.edit(mapping = da) |
---|
104 | elif "Manager" in member.getRoles(): |
---|
105 | pass |
---|
106 | else: |
---|
107 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
108 | if (not to_member_home) and (not to_workspaces): |
---|
109 | redirect_to_portal = True |
---|
110 | |
---|
111 | if to_waeup_student_home: |
---|
112 | #member.setProperties(last_login_time=current,login_time=current) |
---|
113 | #if info['review_state'] == "application_pin_entered": |
---|
114 | if s_review_state == "application_pin_entered": |
---|
115 | return response.redirect("%s/application_edit_form" % student.absolute_url()) |
---|
116 | #elif info['review_state'] == "admitted": |
---|
117 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
118 | return response.redirect("%s/admission_form" % student.absolute_url()) |
---|
119 | #elif info['review_state'] == "clearance_pin_entered": |
---|
120 | elif s_review_state == "clearance_pin_entered": |
---|
121 | return response.redirect("%s/clearance_edit_form" % student.absolute_url()) |
---|
122 | return response.redirect("%s/student_index" % student.absolute_url()) |
---|
123 | |
---|
124 | elif to_member_home: |
---|
125 | redirect_url = mtool.getHomeFolder().absolute_url() |
---|
126 | elif to_workspaces: |
---|
127 | redirect_url = portal.workspaces.absolute_url() |
---|
128 | elif redirect_to_portal: |
---|
129 | redirect_url = portal_absolute_url |
---|
130 | |
---|
131 | REQUEST = context.REQUEST |
---|
132 | RESPONSE = REQUEST.RESPONSE |
---|
133 | |
---|
134 | # Setup skins |
---|
135 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
136 | utool.updateSkinCookie()): |
---|
137 | context.setupCurrentSkin() |
---|
138 | |
---|
139 | # Anonymous |
---|
140 | if is_anon: |
---|
141 | RESPONSE.expireCookie('__ac', path='/') |
---|
142 | return context.user_logged_in_failed() |
---|
143 | |
---|
144 | login_time = member.getProperty('login_time', '2000/01/01') |
---|
145 | first_time = (str(login_time) == '2000/01/01') |
---|
146 | |
---|
147 | ##if first_time and member.has_role('Member') and not member.has_role('Student'): |
---|
148 | ## mtool.createMemberArea() |
---|
149 | ## now = context.ZopeTime() |
---|
150 | ## member.setProperties(last_login_time=now, login_time=now) |
---|
151 | |
---|
152 | if to_member_home or to_workspaces: |
---|
153 | redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in') |
---|
154 | RESPONSE.redirect(redirect_url) |
---|