annotate MoinMoin/userprefs/changepass.py @ 4336:4f3d0b92d1c9

add i18n to the password checker result messages, add request param
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 25 Sep 2008 18:31:24 +0200
parents 7bfd4232cfb7
children eda647742453 a2128aa8b830
rev   line source
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
2 """
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
3 MoinMoin - Password change preferences plugin
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
4
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
5 @copyright: 2001-2004 Juergen Hermann <jh@web.de>,
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
6 2003-2007 MoinMoin:ThomasWaldmann
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
7 2007 MoinMoin:JohannesBerg
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
9 """
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
10
3175
2a3a6cb34e45 pylint findings: fix some harmless stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3122
diff changeset
11 from MoinMoin import user
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
12 from MoinMoin.widget import html
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
13 from MoinMoin.userprefs import UserPrefBase
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
14
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
15
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
16 class Settings(UserPrefBase):
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
17 def __init__(self, request):
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
18 """ Initialize password change form. """
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
19 UserPrefBase.__init__(self, request)
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
20 self.request = request
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
21 self._ = request.getText
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
22 _ = request.getText
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
23 self.cfg = request.cfg
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2997
diff changeset
24 self.title = _("Change password")
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
25 self.name = 'changepass'
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
26
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
27
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
28 def allowed(self):
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
29 return (not 'password' in self.cfg.user_form_remove and
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
30 not 'password' in self.cfg.user_form_disable and
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
31 UserPrefBase.allowed(self) and
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
32 not 'password' in self.request.user.auth_attribs)
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
33
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
34
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
35 def handle_form(self):
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
36 _ = self._
2431
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
37 request = self.request
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
38 form = request.form
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
39
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
40 if form.has_key('cancel'):
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
41 return
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
42
2431
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
43 if request.request_method != 'POST':
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
44 return
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
45
3233
5e120e903ad5 avoid browsers filling in the user's password into first pw field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
46 password = form.get('password1', [''])[0]
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
47 password2 = form.get('password2', [''])[0]
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
48
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
49 # Check if password is given and matches with password repeat
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
50 if password != password2:
3513
7bfd4232cfb7 builtin userprefs plugins: return appropriate message class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3233
diff changeset
51 return 'error', _("Passwords don't match!")
2997
c5cc1a0db4b2 fix password_checker userform code (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2436
diff changeset
52 if not password:
3513
7bfd4232cfb7 builtin userprefs plugins: return appropriate message class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3233
diff changeset
53 return 'error', _("Please specify a password!")
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
54
2431
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
55 pw_checker = request.cfg.password_checker
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
56 if pw_checker:
4336
4f3d0b92d1c9 add i18n to the password checker result messages, add request param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3513
diff changeset
57 pw_error = pw_checker(request, request.user.name, password)
2431
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
58 if pw_error:
3513
7bfd4232cfb7 builtin userprefs plugins: return appropriate message class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3233
diff changeset
59 return 'error', _("Password not acceptable: %s") % pw_error
2431
58260d360f5c password_checker (simple builtin test, optionally using python-crack lib)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2423
diff changeset
60
2436
c8a3a74953f6 remove bogus {SHA} check from changepass
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2431
diff changeset
61 try:
c8a3a74953f6 remove bogus {SHA} check from changepass
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2431
diff changeset
62 self.request.user.enc_password = user.encodePassword(password)
c8a3a74953f6 remove bogus {SHA} check from changepass
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2431
diff changeset
63 self.request.user.save()
3513
7bfd4232cfb7 builtin userprefs plugins: return appropriate message class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3233
diff changeset
64 return 'info', _("Your password has been changed.")
2436
c8a3a74953f6 remove bogus {SHA} check from changepass
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2431
diff changeset
65 except UnicodeError, err:
c8a3a74953f6 remove bogus {SHA} check from changepass
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2431
diff changeset
66 # Should never happen
c8a3a74953f6 remove bogus {SHA} check from changepass
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2431
diff changeset
67 return "Can't encode password: %s" % str(err)
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
68
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
69
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
70 def create_form(self, create_only=False, recover_only=False):
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
71 """ Create the complete HTML form code. """
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
72 _ = self._
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
73 form = self.make_form(html.Text(_("To change your password, "
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
74 "enter a new password twice.")))
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
75
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
76 self.make_row(_('Password'),
3233
5e120e903ad5 avoid browsers filling in the user's password into first pw field
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
77 [html.INPUT(type="password", size=36, name="password1")])
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
78 self.make_row(_('Password repeat'),
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
79 [html.INPUT(type="password", size=36, name="password2")])
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
80
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
81 # Add buttons
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
82 self.make_row('', [
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
83 html.INPUT(type="submit", name='save', value=_("Change password")),
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
84 ' ',
2367
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
85 html.INPUT(type="submit", name='cancel', value=_("Cancel")),
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
86 ])
405032c82324 introduce changepass userprefs plugin
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
diff changeset
87
2368
5fc0717a060f refactor userprefs for more consistent UI
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2367
diff changeset
88 return unicode(form)