source: WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py_old @ 1254

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

logged_in.py slimmed down

File size: 5.8 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 1082 2006-12-18 21:25:01Z henrik $
14"""
15import DateTime
16current = DateTime.DateTime()
17import logging
18logger = logging.getLogger('Member.Login')
19
20
21from urllib import unquote
22
23def checkRedirect(portal, mtool):
24    to_member_home = False
25    to_workspaces = False
26##    has_home = mtool.getHomeFolder()
27##    if has_home:
28##        to_member_home = True
29##    if not has_home and mtool.checkPermission('View', portal.workspaces):
30##        to_workspaces = True
31    return to_member_home, to_workspaces
32
33request = context.REQUEST
34response = request.RESPONSE
35utool = context.portal_url
36mtool = context.portal_membership
37wftool = context.portal_workflow
38portal = utool.getPortalObject()
39portal_absolute_url = portal.absolute_url()
40
41redirect_url = came_from
42redirect_to_portal = False
43to_member_home = False
44to_workspaces = False
45to_waeup_student_home = False
46
47is_anon = mtool.isAnonymousUser()
48member = mtool.getAuthenticatedMember()
49
50if redirect_url and redirect_url.endswith('/logged_out'):
51    redirect_to_portal = True
52else:
53    if not is_anon:
54        if "Student" in member.getRoles():
55            to_waeup_student_home = True
56            students = context.portal_url.getPortalObject().campus.students
57            student = getattr(students,str(member))
58            student_app = getattr(student,'application')
59            student_pume = getattr(student,'pume',None)
60            s_review_state = wftool.getInfoFor(student,'review_state',None)
61            a_review_state = wftool.getInfoFor(student_app,'review_state',None)
62            logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state))
63            app_doc = student_app.getContent()
64            #from Products.zdb import set_trace
65            #set_trace()
66            if s_review_state in ("student_created","admitted") and\
67            a_review_state == 'created' :
68                wftool.doActionFor(student_app,'open')
69                if student_pume is not None:
70                  wftool.doActionFor(student_pume,'close')
71                da = {}
72                pin = request.get('pin')
73                if not pin:
74                    jamb_reg_no = app_doc.jamb_reg_no
75                    for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
76                        res = context.portal_pins(student=reg_no)
77                        if len(res) > 0:
78                            break
79                    if len(res) > 0:
80                        p = res[0].pin
81                        if len(p) > 10:
82                            pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
83                        else:
84                            pin = p
85                da['app_ac_pin'] = pin
86                da['app_ac_date'] = current
87                app_doc.edit(mapping = da)
88            elif s_review_state in ("admitted") and a_review_state == 'opened' and\
89            not app_doc.app_ac_pin:
90                jamb_reg_no = app_doc.jamb_reg_no
91                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
92                    res = context.portal_pins(student=reg_no)
93                    if len(res) > 0:
94                        break
95                if len(res) > 0:
96                    p = res[0].pin
97                    if len(p) > 10:
98                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
99                    else:
100                        pin = p
101                    da = {}
102                    da['app_ac_pin'] = pin
103                    app_doc.edit(mapping = da)
104        elif "Manager" in member.getRoles():
105            pass
106        else:
107            to_member_home, to_workspaces = checkRedirect(portal, mtool)
108
109if (not to_member_home) and (not to_workspaces):
110    redirect_to_portal = True
111
112if to_waeup_student_home:
113    #member.setProperties(last_login_time=current,login_time=current)
114    #if info['review_state'] == "application_pin_entered":
115    if s_review_state == "application_pin_entered":
116        return response.redirect("%s/application_edit_form" % student.absolute_url())
117    #elif info['review_state'] == "admitted":
118    elif s_review_state in ('admitted', 'objection_raised',):
119        return response.redirect("%s/admission_form" % student.absolute_url())
120    #elif info['review_state'] == "clearance_pin_entered":
121    elif s_review_state == "clearance_pin_entered":
122        return response.redirect("%s/clearance_edit_form" % student.absolute_url())
123    return response.redirect("%s/student_index" % student.absolute_url())
124
125elif to_member_home:
126    redirect_url = mtool.getHomeFolder().absolute_url()
127    logger.info('"%s", "logged in to_member_home"' % (member))
128elif to_workspaces:
129    redirect_url = portal.workspaces.absolute_url()
130    logger.info('"%s", "logged in to_workspace"' % (member))
131elif redirect_to_portal:
132    redirect_url = portal_absolute_url
133    logger.info('"%s", "logged in to_portal"' % (member))
134
135REQUEST = context.REQUEST
136RESPONSE = REQUEST.RESPONSE
137
138# Setup skins
139if (getattr(utool, 'updateSkinCookie', False) and
140    utool.updateSkinCookie()):
141    context.setupCurrentSkin()
142
143# Anonymous
144if is_anon:
145    RESPONSE.expireCookie('__ac', path='/')
146    return context.user_logged_in_failed()
147
148login_time = member.getProperty('login_time', '2000/01/01')
149first_time = (str(login_time) == '2000/01/01')
150
151##if first_time and member.has_role('Member') and not member.has_role('Student'):
152##    mtool.createMemberArea()
153##    now = context.ZopeTime()
154##    member.setProperties(last_login_time=now, login_time=now)
155
156if to_member_home or to_workspaces:
157    redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in')
158RESPONSE.redirect(redirect_url)
Note: See TracBrowser for help on using the repository browser.