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')) { exit(1); }
38 * @author Evan Prodromou <evan@status.net>
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
44 class PasswordsettingsAction extends SettingsAction
49 * @return string Title of the page
54 // TRANS: Title for page where to change password.
55 return _m('TITLE','Change password');
59 * Instructions for use
61 * @return instructions for use
64 function getInstructions()
66 // TRANS: Instructions for page where to change password.
67 return _('Change your password.');
70 function showScripts()
72 parent::showScripts();
73 $this->autofocus('oldpassword');
76 function showContent()
78 $this->elementStart('form', array('method' => 'POST',
79 'id' => 'form_password',
80 'class' => 'form_settings',
82 common_local_url('passwordsettings')));
83 $this->elementStart('fieldset');
84 // TRANS: Fieldset legend on page where to change password.
85 $this->element('legend', null, _('Password change'));
86 $this->hidden('token', common_session_token());
89 $this->elementStart('ul', 'form_data');
90 // Users who logged in with OpenID won't have a pwd
91 if ($this->scoped->hasPassword()) {
92 $this->elementStart('li');
93 // TRANS: Field label on page where to change password.
94 $this->password('oldpassword', _('Old password'));
95 $this->elementEnd('li');
97 $this->elementStart('li');
98 // TRANS: Field label on page where to change password.
99 $this->password('newpassword', _('New password'),
100 // TRANS: Field title on page where to change password.
101 _('6 or more characters.'));
102 $this->elementEnd('li');
103 $this->elementStart('li');
104 // TRANS: Field label on page where to change password. In this field the new password should be typed a second time.
105 $this->password('confirm', _m('LABEL','Confirm'),
106 // TRANS: Field title on page where to change password.
107 _('Same as password above.'));
108 $this->elementEnd('li');
109 $this->elementEnd('ul');
111 // TRANS: Button text on page where to change password.
112 $this->submit('changepass', _m('BUTTON','Change'));
114 $this->elementEnd('fieldset');
115 $this->elementEnd('form');
118 protected function doPost()
120 // FIXME: scrub input
122 $newpassword = $this->arg('newpassword');
123 $confirm = $this->arg('confirm');
127 if (strlen($newpassword) < 6) {
128 // TRANS: Form validation error on page where to change password.
129 throw new ClientException(_('Password must be 6 or more characters.'));
130 } else if (0 != strcmp($newpassword, $confirm)) {
131 // TRANS: Form validation error on password change when password confirmation does not match.
132 throw new ClientException(_('Passwords do not match.'));
136 if ($this->scoped->hasPassword()) {
137 $oldpassword = $this->arg('oldpassword');
139 if (!common_check_user($this->scoped->getNickname(), $oldpassword)) {
140 // TRANS: Form validation error on page where to change password.
141 throw new ClientException(_('Incorrect old password.'));
145 if (Event::handle('StartChangePassword', array($this->scoped, $oldpassword, $newpassword))) {
146 //no handler changed the password, so change the password internally
147 $user->setPassword($newpassword);
149 Event::handle('EndChangePassword', array($this->scoped));
152 // TRANS: Form validation notice on page where to change password.
153 return _('Password saved.');