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= |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | """Prepare user login |
---|
11 | modified from cps_default/logged_in.py |
---|
12 | |
---|
13 | $Id: logged_in.py 1778 2007-05-12 16:19:22Z joachim $ |
---|
14 | """ |
---|
15 | try: |
---|
16 | from Products.zdb import set_trace |
---|
17 | except: |
---|
18 | def set_trace(): |
---|
19 | pass |
---|
20 | import DateTime |
---|
21 | current = DateTime.DateTime() |
---|
22 | import logging |
---|
23 | logger = logging.getLogger('Skins.logged_in') |
---|
24 | |
---|
25 | |
---|
26 | from urllib import unquote |
---|
27 | |
---|
28 | request = context.REQUEST |
---|
29 | response = request.RESPONSE |
---|
30 | utool = context.portal_url |
---|
31 | mtool = context.portal_membership |
---|
32 | wftool = context.portal_workflow |
---|
33 | portal = utool.getPortalObject() |
---|
34 | |
---|
35 | redirect_to_portal = False |
---|
36 | is_anon = mtool.isAnonymousUser() |
---|
37 | member = mtool.getAuthenticatedMember() |
---|
38 | load_passport = hasattr(context.waeup_tool,'loadStudentFoto') |
---|
39 | |
---|
40 | if not is_anon: |
---|
41 | if "Student" in member.getRoles(): |
---|
42 | to_waeup_student_home = True |
---|
43 | students = context.portal_url.getPortalObject().campus.students |
---|
44 | student = getattr(students,str(member)) |
---|
45 | student_app = getattr(student,'application',None) |
---|
46 | if request.has_key('returning') and student_app is None: |
---|
47 | email=request.get("email") |
---|
48 | phone=request.get("phone_nr") |
---|
49 | context.waeup_tool.makeStudentData(str(member), |
---|
50 | email=email, |
---|
51 | phone_nr=phone, |
---|
52 | ) |
---|
53 | d = {} |
---|
54 | d['id'] = str(member) |
---|
55 | d['email'] = email |
---|
56 | d['phone'] = phone |
---|
57 | context.students_catalog.modifyRecord(**d) |
---|
58 | elif student_app is None: |
---|
59 | context.waeup_tool.makeStudentData(str(member)) |
---|
60 | student_app = getattr(student,'application',None) |
---|
61 | if 'payments' not in student.objectIds(): |
---|
62 | student.invokeFactory('PaymentsFolder','payments') |
---|
63 | payments = getattr(student,'payments') |
---|
64 | wftool.doActionFor(payments,'open') |
---|
65 | d = {} |
---|
66 | d['Title'] = 'Online Payments' |
---|
67 | payments.getContent().edit(mapping=d) |
---|
68 | student_pume = getattr(student,'pume',None) |
---|
69 | s_review_state = wftool.getInfoFor(student,'review_state',None) |
---|
70 | a_review_state = wftool.getInfoFor(student_app,'review_state',None) |
---|
71 | student_per = getattr(student,'personal',None) |
---|
72 | p_review_state = wftool.getInfoFor(student_per,'review_state',None) |
---|
73 | logger.info('%s logged in, review_state %s' % (member,s_review_state)) |
---|
74 | app_doc = student_app.getContent() |
---|
75 | #from Products.zdb import set_trace;set_trace() |
---|
76 | if load_passport and 'passport' not in app_doc.objectIds(): |
---|
77 | msg = context.waeup_tool.loadStudentFoto(student) |
---|
78 | logger.info('%s, %s' % (member,msg)) |
---|
79 | if s_review_state in ("student_created","admitted") and\ |
---|
80 | a_review_state == 'created' : |
---|
81 | wftool.doActionFor(student_app,'open') |
---|
82 | if student_pume is not None: |
---|
83 | wftool.doActionFor(student_pume,'close') |
---|
84 | da = {} |
---|
85 | pin = request.get('pin') |
---|
86 | if not pin: |
---|
87 | jamb_reg_no = app_doc.jamb_reg_no |
---|
88 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
89 | res = context.portal_pins(student=reg_no) |
---|
90 | if len(res) > 0: |
---|
91 | break |
---|
92 | if len(res) > 0: |
---|
93 | p = res[0].pin |
---|
94 | if len(p) > 10: |
---|
95 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
96 | else: |
---|
97 | pin = p |
---|
98 | da['app_ac_pin'] = pin |
---|
99 | da['app_ac_date'] = current |
---|
100 | app_doc.edit(mapping = da) |
---|
101 | elif s_review_state in ("admitted") and a_review_state == 'opened' and\ |
---|
102 | not app_doc.app_ac_pin: |
---|
103 | jamb_reg_no = app_doc.jamb_reg_no |
---|
104 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
105 | res = context.portal_pins(student=reg_no) |
---|
106 | if len(res) > 0: |
---|
107 | break |
---|
108 | if len(res) > 0: |
---|
109 | p = res[0].pin |
---|
110 | if len(p) > 10: |
---|
111 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
112 | else: |
---|
113 | pin = p |
---|
114 | da = {} |
---|
115 | da['app_ac_pin'] = pin |
---|
116 | app_doc.edit(mapping = da) |
---|
117 | elif s_review_state in ("cleared_and_validated",) and\ |
---|
118 | p_review_state == 'created' : |
---|
119 | wftool.doActionFor(student_per,'open') |
---|
120 | res = context.students_catalog(id = str(member)) |
---|
121 | matric_no = res[0].matric_no |
---|
122 | verdict = res[0].verdict |
---|
123 | if s_review_state == "returning" and not verdict: |
---|
124 | results = context.results_import(matric_no = matric_no) |
---|
125 | if results: |
---|
126 | study_course = getattr(student,'study_course') |
---|
127 | sc_review_state = wftool.getInfoFor(study_course,'review_state',None) |
---|
128 | if sc_review_state != 'opened': |
---|
129 | wftool.doActionFor(study_course,'open') |
---|
130 | study_course_doc =study_course.getContent() |
---|
131 | study_course_doc.edit(mapping={'verdict':results[0].Verdict}) |
---|
132 | if sc_review_state != 'opened': |
---|
133 | wftool.doActionFor(study_course,'close_for_edit') |
---|
134 | is_imported = context.returning_import(matric_no = matric_no) |
---|
135 | if s_review_state == "application_pin_entered": |
---|
136 | redirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
137 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
138 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
139 | elif s_review_state == "clearance_pin_entered": |
---|
140 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
141 | elif s_review_state == "cleared_and_validated": |
---|
142 | redirect_url = "%s/personal_edit_form" % student.absolute_url() |
---|
143 | elif s_review_state == "returning" and is_imported: |
---|
144 | redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
145 | else: |
---|
146 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
147 | else: |
---|
148 | logger.info('%s logged in' % (member)) |
---|
149 | redirect_url = portal.absolute_url() |
---|
150 | #Anonymous |
---|
151 | else: |
---|
152 | response.expireCookie('__ac', path='/') |
---|
153 | return context.user_logged_in_failed() |
---|
154 | |
---|
155 | # Setup skins |
---|
156 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
157 | utool.updateSkinCookie()): |
---|
158 | context.setupCurrentSkin() |
---|
159 | |
---|
160 | response.redirect(redirect_url) |
---|
161 | |
---|