]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/passwordsettings.php
Undefined user in passwordsettings by XRevan86
[quix0rs-gnu-social.git] / actions / passwordsettings.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Change user password
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * Change password
37  *
38  * @category Settings
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45 class PasswordsettingsAction extends SettingsAction
46 {
47     /**
48      * Title of the page
49      *
50      * @return string Title of the page
51      */
52
53     public function title()
54     {
55         // TRANS: Title for page where to change password.
56         return _m('TITLE', 'Change password');
57     }
58
59     /**
60      * Instructions for use
61      *
62      * @return string instructions for use
63      */
64
65     public function getInstructions()
66     {
67         // TRANS: Instructions for page where to change password.
68         return _('Change your password.');
69     }
70
71     public function showScripts()
72     {
73         parent::showScripts();
74         $this->autofocus('oldpassword');
75     }
76
77     public function showContent()
78     {
79         $this->elementStart('form', ['method' => 'POST',
80                                      'id'     => 'form_password',
81                                      'class'  => 'form_settings',
82                                      'action' => 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());
87
88
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');
96         }
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');
110
111         // TRANS: Button text on page where to change password.
112         $this->submit('changepass', _m('BUTTON', 'Change'));
113
114         $this->elementEnd('fieldset');
115         $this->elementEnd('form');
116     }
117
118     protected function doPost()
119     {
120         // FIXME: scrub input
121
122         $newpassword = $this->arg('newpassword');
123         $confirm = $this->arg('confirm');
124
125         // Some validation
126
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         } elseif (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.'));
133         }
134
135         $oldpassword = null;
136         if ($this->scoped->hasPassword()) {
137             $oldpassword = $this->arg('oldpassword');
138
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.'));
142             }
143         }
144
145         if (Event::handle('StartChangePassword', [$this->scoped, $oldpassword, $newpassword])) {
146             // no handler changed the password, so change the password internally
147             $user = $this->scoped->getUser();
148             $user->setPassword($newpassword);
149
150             Event::handle('EndChangePassword', [$this->scoped]);
151         }
152
153         // TRANS: Form validation notice on page where to change password.
154         return _('Password saved.');
155     }
156 }