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