123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class PasswordsettingsAction extends SettingsAction
- {
-
- public function title()
- {
-
- return _m('TITLE', 'Change password');
- }
-
- public function getInstructions()
- {
-
- return _('Change your password.');
- }
- public function showScripts()
- {
- parent::showScripts();
- $this->autofocus('oldpassword');
- }
- public function showContent()
- {
- $this->elementStart('form', ['method' => 'POST',
- 'id' => 'form_password',
- 'class' => 'form_settings',
- 'action' => common_local_url('passwordsettings')]);
- $this->elementStart('fieldset');
-
- $this->element('legend', null, _('Password change'));
- $this->hidden('token', common_session_token());
- $this->elementStart('ul', 'form_data');
-
- if ($this->scoped->hasPassword()) {
- $this->elementStart('li');
-
- $this->password('oldpassword', _('Old password'));
- $this->elementEnd('li');
- }
- $this->elementStart('li');
-
- $this->password('newpassword', _('New password'),
-
- _('6 or more characters.'));
- $this->elementEnd('li');
- $this->elementStart('li');
-
- $this->password('confirm', _m('LABEL', 'Confirm'),
-
- _('Same as password above.'));
- $this->elementEnd('li');
- $this->elementEnd('ul');
-
- $this->submit('changepass', _m('BUTTON', 'Change'));
- $this->elementEnd('fieldset');
- $this->elementEnd('form');
- }
- protected function doPost()
- {
-
- $newpassword = $this->arg('newpassword');
- $confirm = $this->arg('confirm');
-
- if (strlen($newpassword) < 6) {
-
- throw new ClientException(_('Password must be 6 or more characters.'));
- } elseif (0 != strcmp($newpassword, $confirm)) {
-
- throw new ClientException(_('Passwords do not match.'));
- }
- $oldpassword = null;
- if ($this->scoped->hasPassword()) {
- $oldpassword = $this->arg('oldpassword');
- if (!common_check_user($this->scoped->getNickname(), $oldpassword)) {
-
- throw new ClientException(_('Incorrect old password.'));
- }
- }
- if (Event::handle('StartChangePassword', [$this->scoped, $oldpassword, $newpassword])) {
-
- $user = $this->scoped->getUser();
- $user->setPassword($newpassword);
- Event::handle('EndChangePassword', [$this->scoped]);
- }
-
- return _('Password saved.');
- }
- }
|