source: WAeUP_SRP/trunk/skins/waeup_student/retrieve_password.py @ 4008

Last change on this file since 4008 was 3862, checked in by Henrik Bettermann, 16 years ago

fix error message

File size: 3.8 KB
Line 
1##parameters=REQUEST
2# $Id: retrieve_password.py 3367 2008-03-21 13:29:31Z henrik $
3"""
4request Clearance
5"""
6import logging
7logger = logging.getLogger('Skins.retrieve_password')
8validate = REQUEST.has_key("cpsdocument_create_button")
9
10from urllib import urlencode
11
12mhost = context.MailHost
13prop = context.portal_properties
14REQUEST = context.REQUEST
15
16short_msg="""
17From: %s <%s>
18To: %s
19Reply-To: %s
20Subject: %s
21Your SRP Member Details
22-----------------------
23
24Fullname: %s
25Student Id: %s
26Password: %s
27
28"""
29
30mtool = context.portal_membership
31is_anon = mtool.isAnonymousUser()
32member = mtool.getAuthenticatedMember()
33lt = context.portal_layouts
34#pr = context.portal_registration
35
36res,psm,ds = lt.renderLayout('retrieve_password',
37                             'retrieve_password',
38                             context,
39                             mapping=validate and REQUEST,
40                             layout_mode='create',
41                             ob={},
42                             commit=False,
43                             formaction = "retrieve_password",
44                             button = "Send Notification Email",
45                             )
46if psm == 'invalid':
47    reg_no = ds.get('reg_no')
48    try:
49        email = ds.get('email')
50        record = ds.get('record')   
51        email_cat = record.email
52        if email:
53            logger.info('%s: %s does not match %s' % (reg_no,email,email_cat))
54        else:
55            logger.info('%s: no email provided' % (reg_no))
56    except:
57        logger.info('wrong reg number %s' % (reg_no))
58    return context.retrieve_password_form(rendered = res,
59                                 psm = "Please correct your input!",
60                                 #psm = "%s, %s" % (psm,ds),
61                                 firstlayout = True,
62                                 lastlayout = True,
63                                 ds = ds,
64                                 )
65elif psm == '':
66    return context.retrieve_password_form(rendered = res,
67                                 psm = None,
68                                 firstlayout = True,
69                                 lastlayout = True,
70                                 ds = ds,
71                                 )
72elif psm == 'valid':
73
74    reg_no = ds.get('reg_no')
75    record = ds.get('record')
76    s_id = record.id
77    pw = context.waeup_tool.getCredential(s_id)
78
79    if is_anon and not s_id:
80        return context.retrieve_password_form(rendered = res,
81                                 psm = "You are not allowed to call this form in this context. Please try to log in.",
82                                 #psm = "%s, %s" % (psm,ds),
83                                 firstlayout = True,
84                                 lastlayout = True,
85                                 ds = ds,
86                                 )
87    elif not is_anon:
88        return context.retrieve_password_form(rendered = res,
89                                 psm = "You are already logged in!",
90                                 #psm = "%s, %s" % (psm,ds),
91                                 firstlayout = True,
92                                 lastlayout = True,
93                                 ds = ds,
94                                 )
95   
96    logger.info('%s successfully retrieved id %s and password %s' % (reg_no,s_id,pw))
97   
98    email = record.email
99    co_name = prop.email_from_name
100    co_email = prop.email_from_address
101    probtype = 'Your Student Id and Password'
102
103
104    message = short_msg %(co_name,co_email,email,co_email,probtype,record.name,s_id,pw)
105    mhost.send(message)
106
107    return context.retrieve_password_form(rendered = res,
108                             psm = "Notification has been sent!",
109                             firstlayout = True,
110                             lastlayout = True,
111                             ds = ds,
112                             )
113       
114
Note: See TracBrowser for help on using the repository browser.