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