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