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

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

do log also unsuccessful attempts

File size: 3.7 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    email = ds.get('email')
49    record = ds.get('record')   
50    email_cat = record.email
51    if email:
52        logger.info('%s: %s does not match %s' % (reg_no,email,email_cat))
53    else:
54        logger.info('%s: no email provided' % (reg_no))
55    return context.retrieve_password_form(rendered = res,
56                                 psm = "Please correct your input!",
57                                 #psm = "%s, %s" % (psm,ds),
58                                 firstlayout = True,
59                                 lastlayout = True,
60                                 ds = ds,
61                                 )
62elif psm == '':
63    return context.retrieve_password_form(rendered = res,
64                                 psm = None,
65                                 firstlayout = True,
66                                 lastlayout = True,
67                                 ds = ds,
68                                 )
69elif psm == 'valid':
70
71    reg_no = ds.get('reg_no')
72    record = ds.get('record')
73    s_id = record.id
74    pw = context.waeup_tool.getCredential(s_id)
75
76    if is_anon and not s_id:
77        return context.retrieve_password_form(rendered = res,
78                                 psm = "You are not allowed to call this form in this context. Please try to log in.",
79                                 #psm = "%s, %s" % (psm,ds),
80                                 firstlayout = True,
81                                 lastlayout = True,
82                                 ds = ds,
83                                 )
84    elif not is_anon:
85        return context.retrieve_password_form(rendered = res,
86                                 psm = "You are already logged in!",
87                                 #psm = "%s, %s" % (psm,ds),
88                                 firstlayout = True,
89                                 lastlayout = True,
90                                 ds = ds,
91                                 )
92   
93    logger.info('%s successfully retrieved id %s and password %s' % (reg_no,s_id,pw))
94   
95    email = record.email
96    co_name = prop.email_from_name
97    co_email = prop.email_from_address
98    probtype = 'Your Student Id and Password'
99
100
101    message = short_msg %(co_name,co_email,email,co_email,probtype,record.name,s_id,pw)
102    mhost.send(message)
103
104    return context.retrieve_password_form(rendered = res,
105                             psm = "Notification has been sent!",
106                             firstlayout = True,
107                             lastlayout = True,
108                             ds = ds,
109                             )
110       
111
Note: See TracBrowser for help on using the repository browser.