[2217] | 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 1933 2007-06-19 05:05:29Z henrik $ |
---|
| 14 | """ |
---|
| 15 | try: |
---|
| 16 | from Products.zdb import set_trace |
---|
| 17 | except: |
---|
| 18 | def set_trace(): |
---|
| 19 | pass |
---|
| 20 | import DateTime |
---|
[5656] | 21 | import os |
---|
[2217] | 22 | current = DateTime.DateTime() |
---|
| 23 | import logging |
---|
| 24 | logger = logging.getLogger('Skins.logged_in') |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | from urllib import unquote |
---|
| 28 | |
---|
| 29 | request = context.REQUEST |
---|
| 30 | response = request.RESPONSE |
---|
| 31 | utool = context.portal_url |
---|
| 32 | mtool = context.portal_membership |
---|
| 33 | wftool = context.portal_workflow |
---|
| 34 | portal = utool.getPortalObject() |
---|
| 35 | |
---|
| 36 | redirect_to_portal = False |
---|
| 37 | is_anon = mtool.isAnonymousUser() |
---|
| 38 | member = mtool.getAuthenticatedMember() |
---|
[5655] | 39 | member_id = str(member) |
---|
[2710] | 40 | |
---|
[5656] | 41 | cred = context.waeup_tool.getCredentialFromAuthHeader(request) |
---|
| 42 | |
---|
[2710] | 43 | if context.isStaff(): |
---|
[5655] | 44 | is_unsecure = context.waeup_tool.checkGenericPassword(member_id) |
---|
[2710] | 45 | if is_unsecure: |
---|
| 46 | response.expireCookie('__ac', path='/') |
---|
| 47 | return response.redirect("%s/user_logged_in_disabled" % context.portal_url()) |
---|
| 48 | |
---|
[2217] | 49 | #load_passport = hasattr(context.waeup_tool,'loadStudentFoto') |
---|
| 50 | |
---|
| 51 | if not is_anon: |
---|
| 52 | if "Student" in member.getRoles(): |
---|
| 53 | students = context.portal_url.getPortalObject().campus.students |
---|
[5655] | 54 | student = getattr(students,member_id) |
---|
[2217] | 55 | student_app = getattr(student,'application',None) |
---|
| 56 | student_per = getattr(student,'personal',None) |
---|
[5655] | 57 | |
---|
[2412] | 58 | |
---|
[2407] | 59 | ######################################################### |
---|
[2412] | 60 | |
---|
[2407] | 61 | # perform makeStudentData for returning students who login for the first time |
---|
| 62 | # the returning key comes from set_access_data |
---|
[2412] | 63 | |
---|
[3115] | 64 | if request.has_key('returning') and student_per is None: |
---|
[2217] | 65 | email=request.get("email") |
---|
| 66 | phone=request.get("phone_nr") |
---|
[5655] | 67 | context.waeup_tool.makeStudentData(member_id, |
---|
[2217] | 68 | email=email, |
---|
| 69 | phone_nr=phone, |
---|
| 70 | ) |
---|
| 71 | #d = {} |
---|
[5655] | 72 | #d['id'] = member_id |
---|
[2217] | 73 | #d['email'] = email |
---|
| 74 | #d['phone'] = phone |
---|
| 75 | #context.students_catalog.modifyRecord(**d) |
---|
[3115] | 76 | elif student_per is None: |
---|
[5655] | 77 | context.waeup_tool.makeStudentData(member_id) |
---|
[2447] | 78 | |
---|
[2412] | 79 | ######################################################### |
---|
| 80 | |
---|
| 81 | # add missing payments folder |
---|
| 82 | |
---|
[2217] | 83 | if 'payments' not in student.objectIds(): |
---|
| 84 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 85 | payments = getattr(student,'payments') |
---|
| 86 | wftool.doActionFor(payments,'open') |
---|
| 87 | d = {} |
---|
| 88 | d['Title'] = 'Online Payments' |
---|
| 89 | payments.getContent().edit(mapping=d) |
---|
[2412] | 90 | |
---|
| 91 | ######################################################### |
---|
| 92 | |
---|
[2407] | 93 | #student_pume = getattr(student,'pume',None) |
---|
[2217] | 94 | s_review_state = context.getStudentReviewState(student.id) |
---|
| 95 | a_review_state = wftool.getInfoFor(student_app,'review_state',None) |
---|
| 96 | student_per = getattr(student,'personal',None) |
---|
| 97 | p_review_state = wftool.getInfoFor(student_per,'review_state',None) |
---|
| 98 | logger.info('%s logged in, review_state %s' % (member,s_review_state)) |
---|
[2480] | 99 | if student_app is None: |
---|
| 100 | logger.info('%s logged in, without application object' % (member)) |
---|
| 101 | else: |
---|
| 102 | app_doc = student_app.getContent() |
---|
[5655] | 103 | |
---|
| 104 | res = context.students_catalog(id = member_id) |
---|
| 105 | matric_no = res[0].matric_no |
---|
| 106 | jamb_reg_no = res[0].jamb_reg_no |
---|
| 107 | entry_mode = res[0].entry_mode |
---|
| 108 | verdict = res[0].verdict |
---|
| 109 | level = res[0].level |
---|
| 110 | has_level = level |
---|
| 111 | has_verdict = verdict and not verdict == 'N/A' |
---|
[2217] | 112 | |
---|
[2407] | 113 | ######################################################### |
---|
[2412] | 114 | |
---|
[2407] | 115 | # save email and phone of returning students after all objects have been created |
---|
| 116 | |
---|
[2480] | 117 | if request.has_key('returning') and student_app: |
---|
[2217] | 118 | email=request.get("email") |
---|
| 119 | phone=request.get("phone_nr") |
---|
| 120 | # should be always closed, however ... |
---|
[5506] | 121 | #if a_review_state != 'opened': |
---|
| 122 | # wftool.doActionFor(student_app,'open') |
---|
[2217] | 123 | # should be always opened after import, however ... |
---|
| 124 | if p_review_state != 'opened': |
---|
| 125 | wftool.doActionFor(student_per,'open') |
---|
| 126 | per_doc = student_per.getContent() |
---|
[5506] | 127 | #app_doc.edit(mapping = {'app_email' : email}) |
---|
[2217] | 128 | per_doc.edit(mapping = {'email' : email, 'phone' : phone}) |
---|
[5506] | 129 | #wftool.doActionFor(student_app,'close') |
---|
[2412] | 130 | |
---|
| 131 | ######################################################### |
---|
| 132 | |
---|
[2407] | 133 | # look for passport pictures of returning students |
---|
[2217] | 134 | |
---|
[2420] | 135 | if s_review_state == 'returning' and\ |
---|
[5655] | 136 | not context.waeup_tool.picturesExist(('passport',), member_id): |
---|
[2217] | 137 | folder = 'pictures_returning' |
---|
[5655] | 138 | #res = context.students_catalog(id = member_id) |
---|
[2217] | 139 | filename = res[0].matric_no.upper() |
---|
| 140 | msg = context.waeup_tool.loadStudentFoto(student,filename,folder) |
---|
| 141 | logger.info('%s (%s), %s' % (member,s_review_state,msg)) |
---|
[2407] | 142 | |
---|
| 143 | ######################################################### |
---|
[5655] | 144 | |
---|
| 145 | # look for passport pictures of transfer students |
---|
[2412] | 146 | |
---|
[5655] | 147 | if entry_mode == 'transfer' and\ |
---|
| 148 | s_review_state in ('returning','school_fee_paid',) and\ |
---|
| 149 | not context.waeup_tool.picturesExist(('passport',), member_id): |
---|
| 150 | res_both = context.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
| 151 | #set_trace() |
---|
| 152 | if len(res_both) == 2: |
---|
| 153 | for ts in res_both: |
---|
| 154 | if ts.id != member_id: |
---|
| 155 | msg = context.waeup_tool.loadTransferStudentFoto(ts.id,member_id) |
---|
| 156 | logger.info('%s (%s on transfer), %s' % (member,s_review_state,msg)) |
---|
| 157 | |
---|
| 158 | ######################################################### |
---|
| 159 | |
---|
[2407] | 160 | # look for passport pictures of new students |
---|
| 161 | |
---|
[2447] | 162 | if s_review_state in ('admitted', |
---|
[5501] | 163 | 'student_created', |
---|
[2447] | 164 | 'clearance_pin_entered', |
---|
[2420] | 165 | 'clearance_requested' |
---|
| 166 | ) and not context.waeup_tool.picturesExist(('passport',), |
---|
[5655] | 167 | member_id): |
---|
[2217] | 168 | folder = 'pictures_admitted_latest' |
---|
| 169 | filename = app_doc.jamb_reg_no.replace('/','_') |
---|
| 170 | msg = context.waeup_tool.loadStudentFoto(student,filename,folder) |
---|
| 171 | logger.info('%s (%s), %s' % (member,s_review_state,msg)) |
---|
[5496] | 172 | if 'passport picture not found' in msg: |
---|
[5501] | 173 | filename = app_doc.app_reg_pin.replace('-','') |
---|
[5496] | 174 | msg = context.waeup_tool.loadStudentFoto(student,filename,folder) |
---|
| 175 | logger.info('%s (%s), %s' % (member,s_review_state,msg)) |
---|
[2407] | 176 | |
---|
| 177 | ######################################################### |
---|
[2412] | 178 | |
---|
[2407] | 179 | # perform necessary updates for new students |
---|
| 180 | |
---|
| 181 | # 1. add pin and application date to app_doc |
---|
[2412] | 182 | |
---|
[2579] | 183 | if s_review_state == "student_created": |
---|
| 184 | wftool.doActionFor(student,'admit') |
---|
[2710] | 185 | s_review_state = 'admitted' |
---|
[2579] | 186 | |
---|
| 187 | if s_review_state == "admitted" and a_review_state == 'created': |
---|
[2217] | 188 | wftool.doActionFor(student_app,'open') |
---|
[2407] | 189 | #if student_pume is not None: |
---|
| 190 | # wftool.doActionFor(student_pume,'close') |
---|
[2217] | 191 | da = {} |
---|
| 192 | pin = request.get('pin') |
---|
[2412] | 193 | |
---|
| 194 | # if the student comes directly, add missing pin or pin with wrong syntax (fix) |
---|
[2217] | 195 | if not pin: |
---|
| 196 | jamb_reg_no = app_doc.jamb_reg_no |
---|
| 197 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
| 198 | res = context.portal_pins(student=reg_no) |
---|
| 199 | if len(res) > 0: |
---|
| 200 | break |
---|
| 201 | if len(res) > 0: |
---|
| 202 | p = res[0].pin |
---|
| 203 | if len(p) > 10: |
---|
[3998] | 204 | if p.startswith('IPTP'): |
---|
| 205 | pin = "%s-%s-%s" % (p[:4],p[4:5],p[5:]) |
---|
| 206 | else: |
---|
[5517] | 207 | pin = "%s-%s-%s" % (p[:3],p[3:-10],p[-10:]) |
---|
[2217] | 208 | else: |
---|
| 209 | pin = p |
---|
| 210 | da['app_ac_pin'] = pin |
---|
| 211 | da['app_ac_date'] = current |
---|
| 212 | app_doc.edit(mapping = da) |
---|
[2412] | 213 | |
---|
| 214 | # 2. same as 1 but without opening app_doc, assuming that the student already logged in |
---|
| 215 | # but the pin is missing in app_doc (fix) |
---|
| 216 | |
---|
[2217] | 217 | elif s_review_state in ("admitted") and a_review_state == 'opened' and\ |
---|
[3998] | 218 | (not app_doc.app_ac_pin or app_doc.app_ac_pin.startswith('IPT-P')): |
---|
[2217] | 219 | jamb_reg_no = app_doc.jamb_reg_no |
---|
| 220 | for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()): |
---|
| 221 | res = context.portal_pins(student=reg_no) |
---|
| 222 | if len(res) > 0: |
---|
| 223 | break |
---|
| 224 | if len(res) > 0: |
---|
| 225 | p = res[0].pin |
---|
| 226 | if len(p) > 10: |
---|
[3998] | 227 | if p.startswith('IPTP'): |
---|
| 228 | pin = "%s-%s-%s" % (p[:4],p[4:5],p[5:]) |
---|
| 229 | else: |
---|
[5517] | 230 | pin = "%s-%s-%s" % (p[:3],p[3:-10],p[-10:]) |
---|
[2217] | 231 | else: |
---|
| 232 | pin = p |
---|
| 233 | da = {} |
---|
| 234 | da['app_ac_pin'] = pin |
---|
| 235 | app_doc.edit(mapping = da) |
---|
[2412] | 236 | |
---|
| 237 | # 3. open personal object (fix). This should be done in clearance_edit. |
---|
| 238 | |
---|
[2217] | 239 | elif s_review_state in ("cleared_and_validated",) and\ |
---|
| 240 | p_review_state == 'created' : |
---|
| 241 | wftool.doActionFor(student_per,'open') |
---|
[2412] | 242 | |
---|
| 243 | |
---|
[2407] | 244 | ######################################################### |
---|
[2412] | 245 | |
---|
[5022] | 246 | #if matric_no: |
---|
| 247 | # has_results = context.results_import(matric_no = matric_no) |
---|
| 248 | #else: |
---|
| 249 | # has_results = '' |
---|
[2407] | 250 | |
---|
[2447] | 251 | ######################################################### |
---|
[2456] | 252 | |
---|
[2447] | 253 | # fetch current verdict via getVerdict and level via getLevelFromResultsCosCode |
---|
| 254 | |
---|
[5022] | 255 | #if s_review_state in ('returning','school_fee_paid') and not (has_verdict and has_level): |
---|
| 256 | # if has_results: |
---|
| 257 | # study_course = getattr(student,'study_course') |
---|
| 258 | # sc_review_state = wftool.getInfoFor(study_course,'review_state',None) |
---|
| 259 | # dsc = {} |
---|
| 260 | # if not has_verdict and s_review_state == 'returning': |
---|
| 261 | # dsc['current_verdict'] = context.getVerdict(has_results[0].Verdict)[0] |
---|
| 262 | # if not has_level and s_review_state == 'returning': |
---|
| 263 | # lnr = context.getLevelFromResultsCosCode(has_results) |
---|
| 264 | # dsc['current_level'] = "%d00" % lnr |
---|
| 265 | # elif not has_level and s_review_state == 'school_fee_paid': |
---|
| 266 | # lnr = context.getLevelFromResultsCosCode(has_results) |
---|
| 267 | # cv = context.getVerdict(has_results[0].Verdict)[0] |
---|
| 268 | # if cv in ('A','B',): |
---|
| 269 | # lnr += 1 |
---|
| 270 | # dsc['current_level'] = "%d00" % lnr |
---|
| 271 | # dsc['previous_verdict'] = cv |
---|
| 272 | # if sc_review_state != 'opened': |
---|
| 273 | # wftool.doActionFor(study_course,'open') |
---|
| 274 | # study_course_doc =study_course.getContent() |
---|
| 275 | # study_course_doc.edit(mapping = dsc) |
---|
| 276 | # wftool.doActionFor(study_course,'close_for_edit') |
---|
[2412] | 277 | |
---|
[2407] | 278 | ######################################################### |
---|
[2412] | 279 | |
---|
[2407] | 280 | |
---|
| 281 | # determine appropriate redirect url |
---|
| 282 | |
---|
[2217] | 283 | if s_review_state == "application_pin_entered": |
---|
| 284 | redirect_url = "%s/application_edit_form" % student.absolute_url() |
---|
| 285 | elif s_review_state in ('admitted', 'objection_raised',): |
---|
| 286 | redirect_url = "%s/admission_form" % student.absolute_url() |
---|
| 287 | elif s_review_state == "clearance_pin_entered": |
---|
| 288 | redirect_url = "%s/clearance_edit_form" % student.absolute_url() |
---|
| 289 | elif s_review_state == "cleared_and_validated": |
---|
| 290 | redirect_url = "%s/personal_edit_form" % student.absolute_url() |
---|
[3972] | 291 | #elif s_review_state == "returning" and has_results: |
---|
| 292 | # redirect_url = "%s/session_results_view" % student.absolute_url() |
---|
[2217] | 293 | elif s_review_state in ('school_fee_paid','courses_registered'): |
---|
| 294 | redirect_url = "%s/study_course/study_course_view" % student.absolute_url() |
---|
| 295 | else: |
---|
| 296 | redirect_url = "%s/student_index" % student.absolute_url() |
---|
[2407] | 297 | |
---|
| 298 | |
---|
[2217] | 299 | else: |
---|
| 300 | logger.info('%s logged in' % (member)) |
---|
| 301 | redirect_url = portal.absolute_url() |
---|
| 302 | #Anonymous |
---|
| 303 | else: |
---|
[5656] | 304 | logger.info('failed login with %s' % cred) |
---|
[2217] | 305 | response.expireCookie('__ac', path='/') |
---|
| 306 | return context.user_logged_in_failed() |
---|
| 307 | |
---|
| 308 | # Setup skins |
---|
| 309 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
| 310 | utool.updateSkinCookie()): |
---|
| 311 | context.setupCurrentSkin() |
---|
| 312 | |
---|
| 313 | response.redirect(redirect_url) |
---|
| 314 | |
---|