[524] | 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 |
---|
[1092] | 7 | ##parameters= |
---|
[524] | 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | """Prepare user login |
---|
| 11 | modified from cps_default/logged_in.py |
---|
| 12 | |
---|
[805] | 13 | $Id: logged_in.py 1215 2007-01-06 17:33:41Z joachim $ |
---|
[524] | 14 | """ |
---|
[535] | 15 | import DateTime |
---|
| 16 | current = DateTime.DateTime() |
---|
[1004] | 17 | import logging |
---|
[1082] | 18 | logger = logging.getLogger('Member.Login') |
---|
[524] | 19 | |
---|
[1004] | 20 | |
---|
[524] | 21 | from urllib import unquote |
---|
| 22 | |
---|
[535] | 23 | request = context.REQUEST |
---|
| 24 | response = request.RESPONSE |
---|
[524] | 25 | utool = context.portal_url |
---|
| 26 | mtool = context.portal_membership |
---|
[551] | 27 | wftool = context.portal_workflow |
---|
[524] | 28 | portal = utool.getPortalObject() |
---|
| 29 | |
---|
| 30 | redirect_to_portal = False |
---|
| 31 | is_anon = mtool.isAnonymousUser() |
---|
| 32 | member = mtool.getAuthenticatedMember() |
---|
| 33 | |
---|
[1092] | 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)) |
---|
[1215] | 39 | if request.has_key('returning'): |
---|
| 40 | email=request.get("email") |
---|
| 41 | phone=request.get("phone_nr") |
---|
[1158] | 42 | context.waeup_tool.makeStudentData(str(member), |
---|
[1215] | 43 | email=email, |
---|
| 44 | phone_nr=phone, |
---|
[1158] | 45 | ) |
---|
[1215] | 46 | d = {} |
---|
| 47 | d['id'] = str(member) |
---|
| 48 | d['email'] = email |
---|
| 49 | d['phone'] = phone |
---|
| 50 | context.students_catalog.modifyRecord(**d) |
---|
[1151] | 51 | student_app = getattr(student,'application',None) |
---|
| 52 | if student_app is None: |
---|
| 53 | context.waeup_tool.makeStudentData(str(member)) |
---|
| 54 | student_app = getattr(student,'application',None) |
---|
[1092] | 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\ |
---|
[1096] | 63 | a_review_state == 'created' : |
---|
[1092] | 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: |
---|
[999] | 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 |
---|
[1092] | 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\ |
---|
[1096] | 85 | not app_doc.app_ac_pin: |
---|
[1092] | 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": |
---|
[1094] | 101 | rdirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
[1092] | 102 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
[1094] | 103 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
[1092] | 104 | elif s_review_state == "clearance_pin_entered": |
---|
[1094] | 105 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
[1171] | 106 | if s_review_state == "returning": |
---|
[1174] | 107 | redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
[1096] | 108 | else: |
---|
| 109 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
[1092] | 110 | else: |
---|
| 111 | logger.info('"%s", "logged in"' % (member)) |
---|
[1094] | 112 | redirect_url = portal.absolute_url() |
---|
| 113 | #Anonymous |
---|
[1092] | 114 | else: |
---|
| 115 | response.expireCookie('__ac', path='/') |
---|
[524] | 116 | return context.user_logged_in_failed() |
---|
| 117 | |
---|
[1094] | 118 | # Setup skins |
---|
| 119 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
| 120 | utool.updateSkinCookie()): |
---|
| 121 | context.setupCurrentSkin() |
---|
[524] | 122 | |
---|
[1094] | 123 | response.redirect(redirect_url) |
---|
| 124 | |
---|