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

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

fix

  • Property svn:keywords set to Id
File size: 4.9 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=
8##title=
9##
10"""Prepare user login
11modified from cps_default/logged_in.py
12
13$Id: logged_in.py 1242 2007-01-08 17:28:07Z joachim $
14"""
15import DateTime
16current = DateTime.DateTime()
17import logging
18logger = logging.getLogger('Member.Login')
19
20
21from urllib import unquote
22
23request = context.REQUEST
24response = request.RESPONSE
25utool = context.portal_url
26mtool = context.portal_membership
27wftool = context.portal_workflow
28portal = utool.getPortalObject()
29
30redirect_to_portal = False
31is_anon = mtool.isAnonymousUser()
32member = mtool.getAuthenticatedMember()
33
34if not is_anon:
35    if "Student" in member.getRoles():
36        to_waeup_student_home = True
37        students = context.portal_url.getPortalObject().campus.students
38        student = getattr(students,str(member))
39        student_app = getattr(student,'application',None)
40        if request.has_key('returning') and student_app is None:
41            email=request.get("email")
42            phone=request.get("phone_nr")
43            context.waeup_tool.makeStudentData(str(member),
44                                               email=email,
45                                               phone_nr=phone,
46                                               )
47            d = {}
48            d['id'] = str(member)
49            d['email'] = email
50            d['phone'] = phone
51            context.students_catalog.modifyRecord(**d)
52        elif student_app is None:
53            context.waeup_tool.makeStudentData(str(member))
54        student_app = getattr(student,'application',None)
55        if 'payments' not in student.objectIds():
56            student.invokeFactory('PaymentsFolder','payments')
57            payments = getattr(student,'payments')
58            wftool.doActionFor(payments,'open')
59            d = {}
60            d['Title'] = 'Online Payments'
61            payments.getContent().edit(mapping=d)
62        student_pume = getattr(student,'pume',None)
63        s_review_state = wftool.getInfoFor(student,'review_state',None)
64        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
65        logger.info('"%s", "logged in", "review_state %s"' % (member,s_review_state))
66        app_doc = student_app.getContent()
67        #from Products.zdb import set_trace
68        #set_trace()
69        if s_review_state in ("student_created","admitted") and\
70                             a_review_state == 'created' :
71            wftool.doActionFor(student_app,'open')
72            if student_pume is not None:
73              wftool.doActionFor(student_pume,'close')
74            da = {}
75            pin = request.get('pin')
76            if not pin:
77                jamb_reg_no = app_doc.jamb_reg_no
78                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
79                    res = context.portal_pins(student=reg_no)
80                    if len(res) > 0:
81                        break
82                if len(res) > 0:
83                    p = res[0].pin
84                    if len(p) > 10:
85                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
86                    else:
87                        pin = p
88            da['app_ac_pin'] = pin
89            da['app_ac_date'] = current
90            app_doc.edit(mapping = da)
91        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
92                                            not app_doc.app_ac_pin:
93            jamb_reg_no = app_doc.jamb_reg_no
94            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
95                res = context.portal_pins(student=reg_no)
96                if len(res) > 0:
97                    break
98            if len(res) > 0:
99                p = res[0].pin
100                if len(p) > 10:
101                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
102                else:
103                    pin = p
104                da = {}
105                da['app_ac_pin'] = pin
106                app_doc.edit(mapping = da)
107        if s_review_state == "application_pin_entered":
108            rdirect_url = "%s/application_edit_form" % student.absolute_url()
109        elif s_review_state in ('admitted', 'objection_raised',):
110            redirect_url = "%s/admission_form" % student.absolute_url()
111        elif s_review_state == "clearance_pin_entered":
112            redirect_url = "%s/clearance_edit_form" % student.absolute_url()
113        if s_review_state == "returning":
114            redirect_url = "%s/session_results_view" % student.absolute_url()
115        else:
116            redirect_url = "%s/student_index" % student.absolute_url()
117    else:
118        logger.info('"%s", "logged in"' % (member))
119        redirect_url = portal.absolute_url()
120#Anonymous
121else:
122    response.expireCookie('__ac', path='/')
123    return context.user_logged_in_failed()
124
125# Setup skins
126if (getattr(utool, 'updateSkinCookie', False) and
127    utool.updateSkinCookie()):
128    context.setupCurrentSkin()
129
130response.redirect(redirect_url)
131
Note: See TracBrowser for help on using the repository browser.