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

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

logging messages changed

  • Property svn:keywords set to Id
File size: 5.7 KB
RevLine 
[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
11modified from cps_default/logged_in.py
12
[805]13$Id: logged_in.py 1082 2006-12-18 21:25:01Z henrik $
[524]14"""
[535]15import DateTime
16current = DateTime.DateTime()
[1004]17import logging
[1082]18logger = logging.getLogger('Member.Login')
[524]19
[1004]20
[524]21from urllib import unquote
22
23def checkRedirect(portal, mtool):
24    to_member_home = False
25    to_workspaces = False
[603]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
[524]31    return to_member_home, to_workspaces
32
[535]33request = context.REQUEST
34response = request.RESPONSE
[524]35utool = context.portal_url
36mtool = context.portal_membership
[551]37wftool = context.portal_workflow
[524]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
[1021]50if redirect_url and redirect_url.endswith('/logged_out'):
[1009]51    redirect_to_portal = True
[1006]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)
[1016]62            logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state))
[1006]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:
[999]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
[1006]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)
[1082]108
[999]109if (not to_member_home) and (not to_workspaces):
110    redirect_to_portal = True
[524]111
112if to_waeup_student_home:
[933]113    #member.setProperties(last_login_time=current,login_time=current)
[998]114    #if info['review_state'] == "application_pin_entered":
115    if s_review_state == "application_pin_entered":
[1009]116        return response.redirect("%s/application_edit_form" % student.absolute_url())
[998]117    #elif info['review_state'] == "admitted":
[1018]118    elif s_review_state in ('admitted', 'objection_raised',):
[837]119        return response.redirect("%s/admission_form" % student.absolute_url())
[998]120    #elif info['review_state'] == "clearance_pin_entered":
121    elif s_review_state == "clearance_pin_entered":
[1009]122        return response.redirect("%s/clearance_edit_form" % student.absolute_url())
[998]123    return response.redirect("%s/student_index" % student.absolute_url())
[603]124
[524]125elif to_member_home:
126    redirect_url = mtool.getHomeFolder().absolute_url()
[1082]127    logger.info('"%s", "logged in"' % (member))
[524]128elif to_workspaces:
129    redirect_url = portal.workspaces.absolute_url()
[1082]130    logger.info('"%s", "logged in"' % (member))   
[524]131elif redirect_to_portal:
132    redirect_url = portal_absolute_url
[1082]133    logger.info('"%s", "logged in"' % (member))
[524]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
[944]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)
[524]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.