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 1233 2007-01-08 07:19:27Z henrik $ |
---|
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 | |
---|
34 | if not is_anon: |
---|
35 | if "Student" in member.getRoles(): |
---|
36 | to_waeup_student_home = True |
---|
37 | students = context.portal_url.getPortalObject().campus.students |
---|
38 | student = getattr(students,str(member)) |
---|
39 | student_app = getattr(student,'application',None) |
---|
40 | if request.has_key('returning') and student_app is None: |
---|
41 | email=request.get("email") |
---|
42 | phone=request.get("phone_nr") |
---|
43 | context.waeup_tool.makeStudentData(str(member), |
---|
44 | email=email, |
---|
45 | phone_nr=phone, |
---|
46 | ) |
---|
47 | d = {} |
---|
48 | d['id'] = str(member) |
---|
49 | d['email'] = email |
---|
50 | d['phone'] = phone |
---|
51 | context.students_catalog.modifyRecord(**d) |
---|
52 | elif student_app is None: |
---|
53 | context.waeup_tool.makeStudentData(str(member)) |
---|
54 | student_app = getattr(student,'application',None) |
---|
55 | student_pume = getattr(student,'pume',None) |
---|
56 | s_review_state = wftool.getInfoFor(student,'review_state',None) |
---|
57 | a_review_state = wftool.getInfoFor(student_app,'review_state',None) |
---|
58 | logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state)) |
---|
59 | app_doc = student_app.getContent() |
---|
60 | #from Products.zdb import set_trace |
---|
61 | #set_trace() |
---|
62 | if s_review_state in ("student_created","admitted") and\ |
---|
63 | a_review_state == 'created' : |
---|
64 | wftool.doActionFor(student_app,'open') |
---|
65 | if student_pume is not None: |
---|
66 | wftool.doActionFor(student_pume,'close') |
---|
67 | da = {} |
---|
68 | pin = request.get('pin') |
---|
69 | if not pin: |
---|
70 | jamb_reg_no = app_doc.jamb_reg_no |
---|
71 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
72 | res = context.portal_pins(student=reg_no) |
---|
73 | if len(res) > 0: |
---|
74 | break |
---|
75 | if len(res) > 0: |
---|
76 | p = res[0].pin |
---|
77 | if len(p) > 10: |
---|
78 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
79 | else: |
---|
80 | pin = p |
---|
81 | da['app_ac_pin'] = pin |
---|
82 | da['app_ac_date'] = current |
---|
83 | app_doc.edit(mapping = da) |
---|
84 | elif s_review_state in ("admitted") and a_review_state == 'opened' and\ |
---|
85 | not app_doc.app_ac_pin: |
---|
86 | jamb_reg_no = app_doc.jamb_reg_no |
---|
87 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
88 | res = context.portal_pins(student=reg_no) |
---|
89 | if len(res) > 0: |
---|
90 | break |
---|
91 | if len(res) > 0: |
---|
92 | p = res[0].pin |
---|
93 | if len(p) > 10: |
---|
94 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
95 | else: |
---|
96 | pin = p |
---|
97 | da = {} |
---|
98 | da['app_ac_pin'] = pin |
---|
99 | app_doc.edit(mapping = da) |
---|
100 | if s_review_state == "application_pin_entered": |
---|
101 | rdirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
102 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
103 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
104 | elif s_review_state == "clearance_pin_entered": |
---|
105 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
106 | if s_review_state == "returning": |
---|
107 | redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
108 | else: |
---|
109 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
110 | else: |
---|
111 | logger.info('"%s", "logged in"' % (member)) |
---|
112 | redirect_url = portal.absolute_url() |
---|
113 | #Anonymous |
---|
114 | else: |
---|
115 | response.expireCookie('__ac', path='/') |
---|
116 | return context.user_logged_in_failed() |
---|
117 | |
---|
118 | # Setup skins |
---|
119 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
120 | utool.updateSkinCookie()): |
---|
121 | context.setupCurrentSkin() |
---|
122 | |
---|
123 | response.redirect(redirect_url) |
---|
124 | |
---|