source: WAeUP_SRP/trunk/skins/waeup_student/change_password.py @ 9821

Last change on this file since 9821 was 5045, checked in by Henrik Bettermann, 15 years ago

Passwords must not be empty (isn't checked by Password Widget).

  • Property svn:keywords set to Id
File size: 3.2 KB
RevLine 
[1461]1##parameters=
2# $Id: change_password.py 5045 2010-03-10 08:48:18Z henrik $
3"""
[1527]4
[1461]5"""
[1628]6
[1461]7request = context.REQUEST
8import DateTime,logging
[1467]9try:
10    from Products.zdb import set_trace
11except:
12    def set_trace():
13        pass
[1474]14
[1461]15current = DateTime.DateTime()
16#pr = context.portal_registration
[1571]17logger = logging.getLogger('Skins.change_password')
[1461]18validate = request.has_key("change_password")
19students_dir = context.portal_directories.students
[1476]20mtool = context.portal_membership
21member = mtool.getAuthenticatedMember()
22member_id = str(member)
[1461]23lt = context.portal_layouts
[1467]24wt = context.waeup_tool
[1476]25requested_id = context.getStudentId()
26if 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
29elif context.isStaff():
30    student_id = requested_id
31else:
32    student_id = member_id
[1461]33res,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                      )
42if 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                                 )
50elif 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                                 )
59else:
[1467]60    pass
61old_password = request.get('widget__old_password')
62if not wt.checkPassword(student_id,old_password):
[5045]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()
72password = request.get('widget__password')
[5045]73if not len(password):
74    psm = "Please enter a new password!"
75    return context.change_password_form(rendered = res,
76                             psm = psm,
77                             ds = ds,
78                             mode = "edit",
79                             formaction = "change_password",
80                             button = "Change Password",
81                             )
82
[1467]83wt.editPassword(student_id,password)
[3273]84logger.info('%s changed password from %s to %s' % (member_id,old_password,password))
85
86if context.isStaff():
87    return 'Password changed!'
88
[1467]89args = {}
90args['__ac_name'] = student_id
91args['__ac_password'] = password
[3273]92
[1467]93from urllib import urlencode
94url = "%s/logged_in?%s" % (context.absolute_url(),urlencode(args))
95return request.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.