1 | ##parameters= |
---|
2 | # $Id: change_password.py 1669 2007-04-04 06:31:52Z joachim $ |
---|
3 | """ |
---|
4 | |
---|
5 | """ |
---|
6 | |
---|
7 | return |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | request = context.REQUEST |
---|
17 | import DateTime,logging |
---|
18 | try: |
---|
19 | from Products.zdb import set_trace |
---|
20 | except: |
---|
21 | def set_trace(): |
---|
22 | pass |
---|
23 | |
---|
24 | current = DateTime.DateTime() |
---|
25 | #pr = context.portal_registration |
---|
26 | logger = logging.getLogger('Skins.change_password') |
---|
27 | validate = request.has_key("change_password") |
---|
28 | students_dir = context.portal_directories.students |
---|
29 | mtool = context.portal_membership |
---|
30 | member = mtool.getAuthenticatedMember() |
---|
31 | member_id = str(member) |
---|
32 | lt = context.portal_layouts |
---|
33 | wt = context.waeup_tool |
---|
34 | requested_id = context.getStudentId() |
---|
35 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
36 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
37 | return None |
---|
38 | elif context.isStaff(): |
---|
39 | student_id = requested_id |
---|
40 | else: |
---|
41 | student_id = member_id |
---|
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, |
---|
62 | psm = psm, |
---|
63 | ds = ds, |
---|
64 | mode = "edit", |
---|
65 | formaction = "change_password", |
---|
66 | button = "Change Password", |
---|
67 | ) |
---|
68 | else: |
---|
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" |
---|
73 | return context.change_password_form(rendered = res, |
---|
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 |
---|
86 | logger.info('%s changed password from %s to %s' % (member_id,old_password,password)) |
---|
87 | from urllib import urlencode |
---|
88 | url = "%s/logged_in?%s" % (context.absolute_url(),urlencode(args)) |
---|
89 | return request.RESPONSE.redirect(url) |
---|