3 * StatusNet, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
42 * @author Evan Prodromou <evan@status.net>
43 * @author Zach Copley <zach@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
48 class PasswordsettingsAction extends SettingsAction
53 * @return string Title of the page
58 // TRANS: Title for page where to change password.
59 return _m('TITLE','Change password');
63 * Instructions for use
65 * @return instructions for use
68 function getInstructions()
70 // TRANS: Instructions for page where to change password.
71 return _('Change your password.');
74 function showScripts()
76 parent::showScripts();
77 $this->autofocus('oldpassword');
81 * Content area of the page
83 * Shows a form for changing the password
88 function showContent()
90 $user = common_current_user();
92 $this->elementStart('form', array('method' => 'POST',
93 'id' => 'form_password',
94 'class' => 'form_settings',
96 common_local_url('passwordsettings')));
97 $this->elementStart('fieldset');
98 // TRANS: Fieldset legend on page where to change password.
99 $this->element('legend', null, _('Password change'));
100 $this->hidden('token', common_session_token());
103 $this->elementStart('ul', 'form_data');
104 // Users who logged in with OpenID won't have a pwd
105 if ($user->password) {
106 $this->elementStart('li');
107 // TRANS: Field label on page where to change password.
108 $this->password('oldpassword', _('Old password'));
109 $this->elementEnd('li');
111 $this->elementStart('li');
112 // TRANS: Field label on page where to change password.
113 $this->password('newpassword', _('New password'),
114 // TRANS: Field title on page where to change password.
115 _('6 or more characters.'));
116 $this->elementEnd('li');
117 $this->elementStart('li');
118 // TRANS: Field label on page where to change password. In this field the new password should be typed a second time.
119 $this->password('confirm', _m('LABEL','Confirm'),
120 // TRANS: Field title on page where to change password.
121 _('Same as password above.'));
122 $this->elementEnd('li');
123 $this->elementEnd('ul');
125 // TRANS: Button text on page where to change password.
126 $this->submit('changepass', _m('BUTTON','Change'));
128 $this->elementEnd('fieldset');
129 $this->elementEnd('form');
135 * Validate input and save changes. Reload the form with a success
140 function handlePost()
144 $token = $this->trimmed('token');
145 if (!$token || $token != common_session_token()) {
146 // TRANS: Client error displayed when the session token does not match or is not given.
147 $this->showForm(_('There was a problem with your session token. '.
148 'Try again, please.'));
152 $user = common_current_user();
153 assert(!is_null($user)); // should already be checked
155 // FIXME: scrub input
157 $newpassword = $this->arg('newpassword');
158 $confirm = $this->arg('confirm');
162 if (strlen($newpassword) < 6) {
163 // TRANS: Form validation error on page where to change password.
164 $this->showForm(_('Password must be 6 or more characters.'));
166 } else if (0 != strcmp($newpassword, $confirm)) {
167 // TRANS: Form validation error on password change when password confirmation does not match.
168 $this->showForm(_('Passwords do not match.'));
172 if ($user->password) {
173 $oldpassword = $this->arg('oldpassword');
175 if (!common_check_user($user->nickname, $oldpassword)) {
176 // TRANS: Form validation error on page where to change password.
177 $this->showForm(_('Incorrect old password.'));
185 if(Event::handle('StartChangePassword', array($user, $oldpassword, $newpassword))){
186 //no handler changed the password, so change the password internally
187 $original = clone($user);
189 $user->password = common_munge_password($newpassword, $user->id);
191 $val = $user->validate();
193 // TRANS: Form validation error on page where to change password.
194 $this->showForm(_('Error saving user; invalid.'));
198 if (!$user->update($original)) {
199 // TRANS: Server error displayed on page where to change password when password change
200 // TRANS: could not be made because of a server error.
201 $this->serverError(_('Cannot save new password.'));
203 Event::handle('EndChangePassword', array($user));
206 // TRANS: Form validation notice on page where to change password.
207 $this->showForm(_('Password saved.'), true);