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

Last change on this file since 648 was 648, checked in by joachim, 18 years ago

fixed bug in getStudentInfo isManager() instead of isManager
fixed s_id bug

File size: 3.7 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 34693 2006-03-23 17:44:22Z ogrisel $
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'] == "created":
54                student.content_status_modify(workflow_action="enter_application_pin")
55                da = {}
56                pin = request.get('pin')
57                da['app_ac_pin'] = pin
58                da['app_ac_date'] = current
59                info['app_doc'].edit(mapping = da)
60        elif "Manager" in member.getRoles():
61            pass
62        else:
63            to_member_home, to_workspaces = checkRedirect(portal, mtool)
64    if (not to_member_home) and (not to_workspaces):
65        redirect_to_portal = True
66else:
67    redirect_url = unquote(redirect_url)
68    # One can be redirected from an http page while the login is done from an
69    # https page. This is a fix for #1205.
70    # A better option here would be to replace the previous portal_absolute_url
71    # prefix in the redirect_url by the current portal absolute URL.
72    if not redirect_url.startswith(portal_absolute_url):
73        if not is_anon:
74            to_member_home, to_workspaces = checkRedirect(portal, mtool)
75        if (not to_member_home) and (not to_workspaces):
76            redirect_to_portal = True
77
78if to_waeup_student_home:
79    member.setProperties(last_login_time=current,login_time=current)
80    if info['review_state'] == "application_pin_entered":
81        wftool.doActionFor(info['app'],'open',dest_container=info['app'])
82        return response.redirect("%s/passport_entry_view" % student.absolute_url())
83    return response.redirect("%s" % student.absolute_url())
84
85elif to_member_home:
86    redirect_url = mtool.getHomeFolder().absolute_url()
87elif to_workspaces:
88    redirect_url = portal.workspaces.absolute_url()
89elif redirect_to_portal:
90    redirect_url = portal_absolute_url
91
92REQUEST = context.REQUEST
93RESPONSE = REQUEST.RESPONSE
94
95# Setup skins
96if (getattr(utool, 'updateSkinCookie', False) and
97    utool.updateSkinCookie()):
98    context.setupCurrentSkin()
99
100# Anonymous
101if is_anon:
102    RESPONSE.expireCookie('__ac', path='/')
103    return context.user_logged_in_failed()
104
105login_time = member.getProperty('login_time', '2000/01/01')
106first_time = (str(login_time) == '2000/01/01')
107
108if first_time and member.has_role('Member'):
109    mtool.createMemberArea()
110    now = context.ZopeTime()
111    member.setProperties(last_login_time=now, login_time=now)
112
113if to_member_home or to_workspaces:
114    redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in')
115RESPONSE.redirect(redirect_url)
Note: See TracBrowser for help on using the repository browser.