[1461] | 1 | ##parameters= |
---|
| 2 | # $Id: change_password.py 1628 2007-03-23 11:00:24Z henrik $ |
---|
| 3 | """ |
---|
[1527] | 4 | |
---|
[1461] | 5 | """ |
---|
[1628] | 6 | |
---|
| 7 | return |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
[1461] | 16 | request = context.REQUEST |
---|
| 17 | import DateTime,logging |
---|
[1467] | 18 | try: |
---|
| 19 | from Products.zdb import set_trace |
---|
| 20 | except: |
---|
| 21 | def set_trace(): |
---|
| 22 | pass |
---|
[1474] | 23 | |
---|
[1461] | 24 | current = DateTime.DateTime() |
---|
| 25 | #pr = context.portal_registration |
---|
[1571] | 26 | logger = logging.getLogger('Skins.change_password') |
---|
[1461] | 27 | validate = request.has_key("change_password") |
---|
| 28 | students_dir = context.portal_directories.students |
---|
[1476] | 29 | mtool = context.portal_membership |
---|
| 30 | member = mtool.getAuthenticatedMember() |
---|
| 31 | member_id = str(member) |
---|
[1461] | 32 | lt = context.portal_layouts |
---|
[1467] | 33 | wt = context.waeup_tool |
---|
[1476] | 34 | requested_id = context.getStudentId() |
---|
| 35 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
[1571] | 36 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
[1476] | 37 | return None |
---|
| 38 | elif context.isStaff(): |
---|
| 39 | student_id = requested_id |
---|
| 40 | else: |
---|
| 41 | student_id = member_id |
---|
[1461] | 42 | res,psm,ds = lt.renderLayout(layout_id= 'student_change_password', |
---|
| 43 | schema_id= 'student_change_password', |
---|
| 44 | context=context, |
---|
| 45 | mapping=validate and request, |
---|
| 46 | ob = {}, |
---|
| 47 | layout_mode='edit', |
---|
| 48 | button = "Change Password", |
---|
| 49 | commit = False, |
---|
| 50 | ) |
---|
| 51 | if psm == '': |
---|
| 52 | return context.change_password_form(rendered = res, |
---|
| 53 | psm = None, |
---|
| 54 | ds = ds, |
---|
| 55 | mode = "edit", |
---|
| 56 | formaction = "change_password", |
---|
| 57 | button = "Change Password", |
---|
| 58 | ) |
---|
| 59 | elif psm == 'invalid': |
---|
| 60 | psm = "Please correct your input!" |
---|
| 61 | return context.change_password_form(rendered = res, |
---|
[1467] | 62 | psm = psm, |
---|
[1461] | 63 | ds = ds, |
---|
| 64 | mode = "edit", |
---|
| 65 | formaction = "change_password", |
---|
| 66 | button = "Change Password", |
---|
| 67 | ) |
---|
| 68 | else: |
---|
[1467] | 69 | pass |
---|
| 70 | old_password = request.get('widget__old_password') |
---|
| 71 | if not wt.checkPassword(student_id,old_password): |
---|
| 72 | psm = "Old Password is not correct" |
---|
[1461] | 73 | return context.change_password_form(rendered = res, |
---|
[1467] | 74 | psm = psm, |
---|
| 75 | ds = ds, |
---|
| 76 | mode = "edit", |
---|
| 77 | formaction = "change_password", |
---|
| 78 | button = "Change Password", |
---|
| 79 | ) |
---|
| 80 | #set_trace() |
---|
| 81 | password = request.get('widget__password') |
---|
| 82 | wt.editPassword(student_id,password) |
---|
| 83 | args = {} |
---|
| 84 | args['__ac_name'] = student_id |
---|
| 85 | args['__ac_password'] = password |
---|
[1571] | 86 | logger.info('%s changed password from %s to %s' % (member_id,old_password,password)) |
---|
[1467] | 87 | from urllib import urlencode |
---|
| 88 | url = "%s/logged_in?%s" % (context.absolute_url(),urlencode(args)) |
---|
| 89 | return request.RESPONSE.redirect(url) |
---|