[1233] | 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 1285 2007-01-12 16:04:40Z 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() |
---|
[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) |
---|
| 66 | logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state)) |
---|
| 67 | app_doc = student_app.getContent() |
---|
[1285] | 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)) |
---|
[1092] | 72 | if s_review_state in ("student_created","admitted") and\ |
---|
[1096] | 73 | a_review_state == 'created' : |
---|
[1092] | 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: |
---|
[999] | 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 |
---|
[1092] | 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\ |
---|
[1096] | 95 | not app_doc.app_ac_pin: |
---|
[1092] | 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": |
---|
[1094] | 111 | rdirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
[1092] | 112 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
[1094] | 113 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
[1092] | 114 | elif s_review_state == "clearance_pin_entered": |
---|
[1094] | 115 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
[1171] | 116 | if s_review_state == "returning": |
---|
[1174] | 117 | redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
[1096] | 118 | else: |
---|
| 119 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
[1092] | 120 | else: |
---|
| 121 | logger.info('"%s", "logged in"' % (member)) |
---|
[1094] | 122 | redirect_url = portal.absolute_url() |
---|
| 123 | #Anonymous |
---|
[1092] | 124 | else: |
---|
| 125 | response.expireCookie('__ac', path='/') |
---|
[524] | 126 | return context.user_logged_in_failed() |
---|
| 127 | |
---|
[1094] | 128 | # Setup skins |
---|
| 129 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
| 130 | utool.updateSkinCookie()): |
---|
| 131 | context.setupCurrentSkin() |
---|
[524] | 132 | |
---|
[1094] | 133 | response.redirect(redirect_url) |
---|
| 134 | |
---|