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