[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 |
---|
| 7 | ##parameters=came_from=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | """Prepare user login |
---|
| 11 | modified from cps_default/logged_in.py |
---|
| 12 | |
---|
[805] | 13 | $Id: logged_in.py 990 2006-12-05 12:08:24Z joachim $ |
---|
[524] | 14 | """ |
---|
[535] | 15 | import DateTime |
---|
| 16 | current = DateTime.DateTime() |
---|
[524] | 17 | |
---|
| 18 | from urllib import unquote |
---|
| 19 | |
---|
| 20 | def checkRedirect(portal, mtool): |
---|
| 21 | to_member_home = False |
---|
| 22 | to_workspaces = False |
---|
[603] | 23 | ## has_home = mtool.getHomeFolder() |
---|
| 24 | ## if has_home: |
---|
| 25 | ## to_member_home = True |
---|
| 26 | ## if not has_home and mtool.checkPermission('View', portal.workspaces): |
---|
| 27 | ## to_workspaces = True |
---|
[524] | 28 | return to_member_home, to_workspaces |
---|
| 29 | |
---|
[535] | 30 | request = context.REQUEST |
---|
| 31 | response = request.RESPONSE |
---|
[524] | 32 | utool = context.portal_url |
---|
| 33 | mtool = context.portal_membership |
---|
[551] | 34 | wftool = context.portal_workflow |
---|
[524] | 35 | portal = utool.getPortalObject() |
---|
| 36 | portal_absolute_url = portal.absolute_url() |
---|
| 37 | |
---|
| 38 | redirect_url = came_from |
---|
| 39 | redirect_to_portal = False |
---|
| 40 | to_member_home = False |
---|
| 41 | to_workspaces = False |
---|
| 42 | to_waeup_student_home = False |
---|
| 43 | |
---|
| 44 | is_anon = mtool.isAnonymousUser() |
---|
| 45 | member = mtool.getAuthenticatedMember() |
---|
| 46 | |
---|
[990] | 47 | if True or not redirect_url or redirect_url.endswith('/logged_out'): |
---|
[524] | 48 | if not is_anon: |
---|
| 49 | if "Student" in member.getRoles(): |
---|
[535] | 50 | to_waeup_student_home = True |
---|
| 51 | info = context.getStudentInfo() |
---|
| 52 | student = info['student'] |
---|
[828] | 53 | if info['review_state'] in ("student_created","admitted") and\ |
---|
| 54 | wftool.getInfoFor(info['app'],'review_state',None) == 'created' : |
---|
[767] | 55 | #student.content_status_modify(workflow_action="enter_clearance_pin") |
---|
[803] | 56 | wftool.doActionFor(info['app'],'open') |
---|
| 57 | #wftool.doActionFor(info['pume'],'close') |
---|
[796] | 58 | if info['pume'] is not None: |
---|
[803] | 59 | wftool.doActionFor(info['pume'],'close') |
---|
[524] | 60 | da = {} |
---|
| 61 | pin = request.get('pin') |
---|
[990] | 62 | if not pin: |
---|
| 63 | jamb_reg_no = info['app_doc'].jamb_reg_no |
---|
| 64 | res = context.portal_pins(student=jamb_reg_no) |
---|
| 65 | if len(res) == 1: |
---|
| 66 | p = res[0].pin |
---|
| 67 | pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:]) |
---|
[979] | 68 | ## email = request.get('email') |
---|
[766] | 69 | app_doc = info['app_doc'] |
---|
[524] | 70 | da['app_ac_pin'] = pin |
---|
[979] | 71 | ## da['app_email'] = email |
---|
[524] | 72 | da['app_ac_date'] = current |
---|
[766] | 73 | app_doc.edit(mapping = da) |
---|
[785] | 74 | ## dc = {} |
---|
| 75 | ## dc['clr_ac_pin'] = pin |
---|
| 76 | ## dc['entry_date'] = current |
---|
| 77 | ## dc['session'] = "%s" % current.year() |
---|
| 78 | ## dc['lga'] = app_doc.jamb_lga |
---|
| 79 | ## info['clear_doc'].edit(mapping = dc) |
---|
[524] | 80 | elif "Manager" in member.getRoles(): |
---|
| 81 | pass |
---|
| 82 | else: |
---|
| 83 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
| 84 | if (not to_member_home) and (not to_workspaces): |
---|
| 85 | redirect_to_portal = True |
---|
| 86 | else: |
---|
| 87 | redirect_url = unquote(redirect_url) |
---|
| 88 | # One can be redirected from an http page while the login is done from an |
---|
| 89 | # https page. This is a fix for #1205. |
---|
| 90 | # A better option here would be to replace the previous portal_absolute_url |
---|
| 91 | # prefix in the redirect_url by the current portal absolute URL. |
---|
| 92 | if not redirect_url.startswith(portal_absolute_url): |
---|
| 93 | if not is_anon: |
---|
| 94 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
| 95 | if (not to_member_home) and (not to_workspaces): |
---|
| 96 | redirect_to_portal = True |
---|
| 97 | |
---|
| 98 | if to_waeup_student_home: |
---|
[933] | 99 | #member.setProperties(last_login_time=current,login_time=current) |
---|
[537] | 100 | if info['review_state'] == "application_pin_entered": |
---|
[770] | 101 | return response.redirect("%s/application_edit" % student.absolute_url()) |
---|
[796] | 102 | elif info['review_state'] == "admitted": |
---|
[837] | 103 | return response.redirect("%s/admission_form" % student.absolute_url()) |
---|
[770] | 104 | elif info['review_state'] == "clearance_pin_entered": |
---|
[837] | 105 | return response.redirect("%s/clearance_edit" % student.absolute_url()) |
---|
[742] | 106 | return response.redirect("%s/student_index" % info['url']) |
---|
[603] | 107 | |
---|
[524] | 108 | elif to_member_home: |
---|
| 109 | redirect_url = mtool.getHomeFolder().absolute_url() |
---|
| 110 | elif to_workspaces: |
---|
| 111 | redirect_url = portal.workspaces.absolute_url() |
---|
| 112 | elif redirect_to_portal: |
---|
| 113 | redirect_url = portal_absolute_url |
---|
| 114 | |
---|
| 115 | REQUEST = context.REQUEST |
---|
| 116 | RESPONSE = REQUEST.RESPONSE |
---|
| 117 | |
---|
| 118 | # Setup skins |
---|
| 119 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
| 120 | utool.updateSkinCookie()): |
---|
| 121 | context.setupCurrentSkin() |
---|
| 122 | |
---|
| 123 | # Anonymous |
---|
| 124 | if is_anon: |
---|
| 125 | RESPONSE.expireCookie('__ac', path='/') |
---|
| 126 | return context.user_logged_in_failed() |
---|
| 127 | |
---|
| 128 | login_time = member.getProperty('login_time', '2000/01/01') |
---|
| 129 | first_time = (str(login_time) == '2000/01/01') |
---|
| 130 | |
---|
[944] | 131 | ##if first_time and member.has_role('Member') and not member.has_role('Student'): |
---|
| 132 | ## mtool.createMemberArea() |
---|
| 133 | ## now = context.ZopeTime() |
---|
| 134 | ## member.setProperties(last_login_time=now, login_time=now) |
---|
[524] | 135 | |
---|
| 136 | if to_member_home or to_workspaces: |
---|
| 137 | redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in') |
---|
| 138 | RESPONSE.redirect(redirect_url) |
---|