source: WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py @ 862

Last change on this file since 862 was 837, checked in by Henrik Bettermann, 18 years ago

clearance_view and admission_form re-built

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