[3858] | 1 | ##parameters=REQUEST |
---|
| 2 | # $Id: retrieve_password.py 3367 2008-03-21 13:29:31Z henrik $ |
---|
| 3 | """ |
---|
| 4 | request Clearance |
---|
| 5 | """ |
---|
| 6 | import logging |
---|
| 7 | logger = logging.getLogger('Skins.retrieve_password') |
---|
| 8 | validate = REQUEST.has_key("cpsdocument_create_button") |
---|
| 9 | |
---|
| 10 | from urllib import urlencode |
---|
| 11 | |
---|
| 12 | mhost = context.MailHost |
---|
| 13 | prop = context.portal_properties |
---|
| 14 | REQUEST = context.REQUEST |
---|
| 15 | |
---|
[3859] | 16 | short_msg=""" |
---|
| 17 | From: %s <%s> |
---|
| 18 | To: %s |
---|
| 19 | Reply-To: %s |
---|
| 20 | Subject: %s |
---|
| 21 | Your SRP Member Details |
---|
| 22 | ----------------------- |
---|
[3858] | 23 | |
---|
[3859] | 24 | Fullname: %s |
---|
| 25 | Student Id: %s |
---|
| 26 | Password: %s |
---|
| 27 | |
---|
| 28 | """ |
---|
| 29 | |
---|
[3858] | 30 | mtool = context.portal_membership |
---|
| 31 | is_anon = mtool.isAnonymousUser() |
---|
| 32 | member = mtool.getAuthenticatedMember() |
---|
| 33 | lt = context.portal_layouts |
---|
| 34 | #pr = context.portal_registration |
---|
| 35 | |
---|
| 36 | res,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 | ) |
---|
| 46 | if psm == 'invalid': |
---|
[3862] | 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)) |
---|
[3858] | 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 | ) |
---|
| 65 | elif psm == '': |
---|
| 66 | return context.retrieve_password_form(rendered = res, |
---|
| 67 | psm = None, |
---|
| 68 | firstlayout = True, |
---|
| 69 | lastlayout = True, |
---|
| 70 | ds = ds, |
---|
| 71 | ) |
---|
| 72 | elif 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 | |
---|
[3859] | 103 | |
---|
[3858] | 104 | message = short_msg %(co_name,co_email,email,co_email,probtype,record.name,s_id,pw) |
---|
[3859] | 105 | mhost.send(message) |
---|
[3858] | 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 | |
---|