123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class PasswordsettingsAction extends SettingsAction
- {
-
- function title()
- {
-
- return _m('TITLE','Change password');
- }
-
- function getInstructions()
- {
-
- return _('Change your password.');
- }
- function showScripts()
- {
- parent::showScripts();
- $this->autofocus('oldpassword');
- }
-
- function showContent()
- {
- $user = common_current_user();
- $this->elementStart('form', array('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 ($user->password) {
- $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');
- }
-
- function handlePost()
- {
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
-
- $this->showForm(_('There was a problem with your session token. '.
- 'Try again, please.'));
- return;
- }
- $user = common_current_user();
- assert(!is_null($user));
-
- $newpassword = $this->arg('newpassword');
- $confirm = $this->arg('confirm');
-
- if (strlen($newpassword) < 6) {
-
- $this->showForm(_('Password must be 6 or more characters.'));
- return;
- } else if (0 != strcmp($newpassword, $confirm)) {
-
- $this->showForm(_('Passwords do not match.'));
- return;
- }
- if ($user->password) {
- $oldpassword = $this->arg('oldpassword');
- if (!common_check_user($user->nickname, $oldpassword)) {
-
- $this->showForm(_('Incorrect old password.'));
- return;
- }
- }else{
- $oldpassword = null;
- }
- $success = false;
- if(Event::handle('StartChangePassword', array($user, $oldpassword, $newpassword))){
-
- $original = clone($user);
- $user->password = common_munge_password($newpassword, $user->id);
- $val = $user->validate();
- if ($val !== true) {
-
- $this->showForm(_('Error saving user; invalid.'));
- return;
- }
- if (!$user->update($original)) {
-
-
- $this->serverError(_('Cannot save new password.'));
- }
- Event::handle('EndChangePassword', array($user));
- }
-
- $this->showForm(_('Password saved.'), true);
- }
- }
|