[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 | |
---|
| 13 | $Id: logged_in.py 34693 2006-03-23 17:44:22Z ogrisel $ |
---|
| 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 | |
---|
| 47 | if not redirect_url or redirect_url.endswith('/logged_out'): |
---|
| 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'] |
---|
[766] | 53 | if info['review_state'] in ("student_created","admitted"): |
---|
[767] | 54 | #student.content_status_modify(workflow_action="enter_clearance_pin") |
---|
[659] | 55 | wftool.doActionFor(info['app'],'open',dest_container=info['app']) |
---|
[524] | 56 | da = {} |
---|
| 57 | pin = request.get('pin') |
---|
[788] | 58 | email = request.get('email') |
---|
[766] | 59 | app_doc = info['app_doc'] |
---|
[524] | 60 | da['app_ac_pin'] = pin |
---|
[788] | 61 | da['app_email'] = email |
---|
[524] | 62 | da['app_ac_date'] = current |
---|
[766] | 63 | app_doc.edit(mapping = da) |
---|
[785] | 64 | ## dc = {} |
---|
| 65 | ## dc['clr_ac_pin'] = pin |
---|
| 66 | ## dc['entry_date'] = current |
---|
| 67 | ## dc['session'] = "%s" % current.year() |
---|
| 68 | ## dc['lga'] = app_doc.jamb_lga |
---|
| 69 | ## info['clear_doc'].edit(mapping = dc) |
---|
[524] | 70 | elif "Manager" in member.getRoles(): |
---|
| 71 | pass |
---|
| 72 | else: |
---|
| 73 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
| 74 | if (not to_member_home) and (not to_workspaces): |
---|
| 75 | redirect_to_portal = True |
---|
| 76 | else: |
---|
| 77 | redirect_url = unquote(redirect_url) |
---|
| 78 | # One can be redirected from an http page while the login is done from an |
---|
| 79 | # https page. This is a fix for #1205. |
---|
| 80 | # A better option here would be to replace the previous portal_absolute_url |
---|
| 81 | # prefix in the redirect_url by the current portal absolute URL. |
---|
| 82 | if not redirect_url.startswith(portal_absolute_url): |
---|
| 83 | if not is_anon: |
---|
| 84 | to_member_home, to_workspaces = checkRedirect(portal, mtool) |
---|
| 85 | if (not to_member_home) and (not to_workspaces): |
---|
| 86 | redirect_to_portal = True |
---|
| 87 | |
---|
| 88 | if to_waeup_student_home: |
---|
| 89 | member.setProperties(last_login_time=current,login_time=current) |
---|
[537] | 90 | if info['review_state'] == "application_pin_entered": |
---|
[770] | 91 | return response.redirect("%s/application_edit" % student.absolute_url()) |
---|
| 92 | elif info['review_state'] == "clearance_pin_entered": |
---|
| 93 | return response.redirect("%s/clearance_edit" % student.absolute_url()) |
---|
[742] | 94 | return response.redirect("%s/student_index" % info['url']) |
---|
[603] | 95 | |
---|
[524] | 96 | elif to_member_home: |
---|
| 97 | redirect_url = mtool.getHomeFolder().absolute_url() |
---|
| 98 | elif to_workspaces: |
---|
| 99 | redirect_url = portal.workspaces.absolute_url() |
---|
| 100 | elif redirect_to_portal: |
---|
| 101 | redirect_url = portal_absolute_url |
---|
| 102 | |
---|
| 103 | REQUEST = context.REQUEST |
---|
| 104 | RESPONSE = REQUEST.RESPONSE |
---|
| 105 | |
---|
| 106 | # Setup skins |
---|
| 107 | if (getattr(utool, 'updateSkinCookie', False) and |
---|
| 108 | utool.updateSkinCookie()): |
---|
| 109 | context.setupCurrentSkin() |
---|
| 110 | |
---|
| 111 | # Anonymous |
---|
| 112 | if is_anon: |
---|
| 113 | RESPONSE.expireCookie('__ac', path='/') |
---|
| 114 | return context.user_logged_in_failed() |
---|
| 115 | |
---|
| 116 | login_time = member.getProperty('login_time', '2000/01/01') |
---|
| 117 | first_time = (str(login_time) == '2000/01/01') |
---|
| 118 | |
---|
| 119 | if first_time and member.has_role('Member'): |
---|
| 120 | mtool.createMemberArea() |
---|
| 121 | now = context.ZopeTime() |
---|
| 122 | member.setProperties(last_login_time=now, login_time=now) |
---|
| 123 | |
---|
| 124 | if to_member_home or to_workspaces: |
---|
| 125 | redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in') |
---|
| 126 | RESPONSE.redirect(redirect_url) |
---|