[1346] | 1 | ## Script (Python) "logged_in" |
---|
[524] | 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 1347 2007-01-25 10:34:33Z henrik $ |
---|
[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() |
---|
[1285] | 33 | load_passport = hasattr(context.waeup_tool,'loadStudentFoto') |
---|
[524] | 34 | |
---|
[1092] | 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)) |
---|
[1228] | 40 | student_app = getattr(student,'application',None) |
---|
| 41 | if request.has_key('returning') and student_app is None: |
---|
[1215] | 42 | email=request.get("email") |
---|
| 43 | phone=request.get("phone_nr") |
---|
[1158] | 44 | context.waeup_tool.makeStudentData(str(member), |
---|
[1215] | 45 | email=email, |
---|
| 46 | phone_nr=phone, |
---|
[1158] | 47 | ) |
---|
[1215] | 48 | d = {} |
---|
| 49 | d['id'] = str(member) |
---|
| 50 | d['email'] = email |
---|
| 51 | d['phone'] = phone |
---|
| 52 | context.students_catalog.modifyRecord(**d) |
---|
[1231] | 53 | elif student_app is None: |
---|
[1151] | 54 | context.waeup_tool.makeStudentData(str(member)) |
---|
| 55 | student_app = getattr(student,'application',None) |
---|
[1241] | 56 | if 'payments' not in student.objectIds(): |
---|
| 57 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 58 | payments = getattr(student,'payments') |
---|
[1242] | 59 | wftool.doActionFor(payments,'open') |
---|
[1241] | 60 | d = {} |
---|
| 61 | d['Title'] = 'Online Payments' |
---|
| 62 | payments.getContent().edit(mapping=d) |
---|
[1092] | 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) |
---|
[1347] | 66 | student_per = getattr(student,'personal',None) |
---|
| 67 | p_review_state = wftool.getInfoFor(student_per,'review_state',None) |
---|
[1092] | 68 | logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state)) |
---|
| 69 | app_doc = student_app.getContent() |
---|
[1285] | 70 | #from Products.zdb import set_trace;set_trace() |
---|
| 71 | if load_passport and 'passport' not in app_doc.objectIds(): |
---|
| 72 | msg = context.waeup_tool.loadStudentFoto(student) |
---|
| 73 | logger.info('"%s", "%s"' % (member,msg)) |
---|
[1092] | 74 | if s_review_state in ("student_created","admitted") and\ |
---|
[1096] | 75 | a_review_state == 'created' : |
---|
[1092] | 76 | wftool.doActionFor(student_app,'open') |
---|
| 77 | if student_pume is not None: |
---|
| 78 | wftool.doActionFor(student_pume,'close') |
---|
| 79 | da = {} |
---|
| 80 | pin = request.get('pin') |
---|
| 81 | if not pin: |
---|
[999] | 82 | jamb_reg_no = app_doc.jamb_reg_no |
---|
| 83 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
| 84 | res = context.portal_pins(student=reg_no) |
---|
| 85 | if len(res) > 0: |
---|
| 86 | break |
---|
| 87 | if len(res) > 0: |
---|
| 88 | p = res[0].pin |
---|
| 89 | if len(p) > 10: |
---|
| 90 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
| 91 | else: |
---|
| 92 | pin = p |
---|
[1092] | 93 | da['app_ac_pin'] = pin |
---|
| 94 | da['app_ac_date'] = current |
---|
| 95 | app_doc.edit(mapping = da) |
---|
| 96 | elif s_review_state in ("admitted") and a_review_state == 'opened' and\ |
---|
[1096] | 97 | not app_doc.app_ac_pin: |
---|
[1092] | 98 | jamb_reg_no = app_doc.jamb_reg_no |
---|
| 99 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
| 100 | res = context.portal_pins(student=reg_no) |
---|
| 101 | if len(res) > 0: |
---|
| 102 | break |
---|
| 103 | if len(res) > 0: |
---|
| 104 | p = res[0].pin |
---|
| 105 | if len(p) > 10: |
---|
| 106 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
| 107 | else: |
---|
| 108 | pin = p |
---|
| 109 | da = {} |
---|
| 110 | da['app_ac_pin'] = pin |
---|
| 111 | app_doc.edit(mapping = da) |
---|
[1347] | 112 | elif s_review_state in ("cleared_and_validated",) and\ |
---|
| 113 | p_review_state == 'created' : |
---|
| 114 | wftool.doActionFor(student_per,'open') |
---|
| 115 | |
---|
[1092] | 116 | if s_review_state == "application_pin_entered": |
---|
[1344] | 117 | redirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
[1092] | 118 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
[1094] | 119 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
[1092] | 120 | elif s_review_state == "clearance_pin_entered": |
---|
[1094] | 121 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
[1347] | 122 | elif s_review_state == "cleared_and_validated": |
---|
| 123 | redirect_url = "%s/personal_edit_form" % student.absolute_url() |
---|
[1344] | 124 | elif s_review_state == "returning": |
---|
[1174] | 125 | redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
[1096] | 126 | else: |
---|
| 127 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
[1092] | 128 | else: |
---|
| 129 | logger.info('"%s", "logged in"' % (member)) |
---|
[1094] | 130 | redirect_url = portal.absolute_url() |
---|
| 131 | #Anonymous |
---|
[1092] | 132 | else: |
---|
| 133 | response.expireCookie('__ac', path='/') |
---|
[524] | 134 | return context.user_logged_in_failed() |
---|
| 135 | |
---|
[1094] | 136 | # Setup skins |
---|
| 137 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
| 138 | utool.updateSkinCookie()): |
---|
| 139 | context.setupCurrentSkin() |
---|
[524] | 140 | |
---|
[1094] | 141 | response.redirect(redirect_url) |
---|
| 142 | |
---|