2008-05-16 01:28:44 +09:00
|
|
|
<?php
|
2008-05-19 21:27:08 +09:00
|
|
|
/*
|
2008-05-16 01:28:44 +09:00
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
2008-05-19 21:27:08 +09:00
|
|
|
*
|
2008-05-16 01:28:44 +09:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-05-19 21:27:08 +09:00
|
|
|
*
|
2008-05-16 01:28:44 +09:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2008-05-19 21:27:08 +09:00
|
|
|
*
|
2008-05-16 01:28:44 +09:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-18 00:47:01 +09:00
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
2008-05-16 01:28:44 +09:00
|
|
|
|
2008-05-18 02:54:16 +09:00
|
|
|
require_once(INSTALLDIR.'/lib/settingsaction.php');
|
|
|
|
|
2008-05-16 01:28:44 +09:00
|
|
|
class PasswordAction extends SettingsAction {
|
2008-05-19 21:27:08 +09:00
|
|
|
|
2008-07-01 02:03:42 +09:00
|
|
|
function get_instructions() {
|
2008-07-08 18:45:31 +09:00
|
|
|
return _('You can change your password here. Choose a good one!');
|
2008-06-18 12:57:39 +09:00
|
|
|
}
|
2008-07-01 02:03:42 +09:00
|
|
|
|
2008-06-18 12:57:39 +09:00
|
|
|
function show_form($msg=NULL, $success=false) {
|
2008-07-08 13:12:10 +09:00
|
|
|
$user = common_current_user();
|
2008-07-08 18:45:31 +09:00
|
|
|
$this->form_header(_('Change password'), $msg, $success);
|
2008-08-29 10:45:15 +09:00
|
|
|
$token = common_session_token();
|
2008-07-02 22:15:07 +09:00
|
|
|
common_element_start('form', array('method' => 'post',
|
2008-05-16 01:28:44 +09:00
|
|
|
'id' => 'password',
|
2008-05-19 21:27:08 +09:00
|
|
|
'action' =>
|
2008-05-16 01:28:44 +09:00
|
|
|
common_local_url('password')));
|
2008-08-29 10:45:15 +09:00
|
|
|
common_hidden('token', $token);
|
2008-07-08 13:12:10 +09:00
|
|
|
# Users who logged in with OpenID won't have a pwd
|
|
|
|
if ($user->password) {
|
2008-07-08 18:45:31 +09:00
|
|
|
common_password('oldpassword', _('Old password'));
|
2008-07-08 13:12:10 +09:00
|
|
|
}
|
2008-07-08 18:45:31 +09:00
|
|
|
common_password('newpassword', _('New password'),
|
|
|
|
_('6 or more characters'));
|
|
|
|
common_password('confirm', _('Confirm'),
|
|
|
|
_('same as password above'));
|
|
|
|
common_submit('submit', _('Change'));
|
2008-05-18 02:04:30 +09:00
|
|
|
common_element_end('form');
|
2008-05-19 22:21:18 +09:00
|
|
|
common_show_footer();
|
2008-05-16 01:28:44 +09:00
|
|
|
}
|
2008-05-19 21:27:08 +09:00
|
|
|
|
2008-05-16 01:28:44 +09:00
|
|
|
function handle_post() {
|
|
|
|
|
|
|
|
$user = common_current_user();
|
|
|
|
assert(!is_null($user)); # should already be checked
|
2008-05-19 21:27:08 +09:00
|
|
|
|
2008-05-16 01:28:44 +09:00
|
|
|
# FIXME: scrub input
|
|
|
|
|
|
|
|
$newpassword = $this->arg('newpassword');
|
|
|
|
$confirm = $this->arg('confirm');
|
2008-08-29 10:45:15 +09:00
|
|
|
$token = $this->arg('token');
|
|
|
|
|
|
|
|
if (!$token || $token != common_session_token()) {
|
|
|
|
$this->show_form(_('There was a problem with your session token. Try again, please.'));
|
2008-08-29 11:37:31 +09:00
|
|
|
return;
|
2008-08-29 10:45:15 +09:00
|
|
|
} else if (0 != strcmp($newpassword, $confirm)) {
|
2008-07-13 14:37:48 +09:00
|
|
|
$this->show_form(_('Passwords don\'t match.'));
|
2008-05-16 01:28:44 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-08 13:12:10 +09:00
|
|
|
if ($user->password) {
|
|
|
|
$oldpassword = $this->arg('oldpassword');
|
2008-07-08 18:45:31 +09:00
|
|
|
|
2008-07-08 13:12:10 +09:00
|
|
|
if (!common_check_user($user->nickname, $oldpassword)) {
|
2008-07-08 18:45:31 +09:00
|
|
|
$this->show_form(_('Incorrect old password'));
|
2008-07-08 13:12:10 +09:00
|
|
|
return;
|
|
|
|
}
|
2008-05-16 01:28:44 +09:00
|
|
|
}
|
2008-05-19 21:27:08 +09:00
|
|
|
|
|
|
|
$original = clone($user);
|
|
|
|
|
2008-05-16 01:28:44 +09:00
|
|
|
$user->password = common_munge_password($newpassword, $user->id);
|
2008-05-19 21:27:08 +09:00
|
|
|
|
2008-05-21 04:10:32 +09:00
|
|
|
$val = $user->validate();
|
|
|
|
if ($val !== TRUE) {
|
2008-07-08 18:45:31 +09:00
|
|
|
$this->show_form(_('Error saving user; invalid.'));
|
2008-05-21 04:10:32 +09:00
|
|
|
return;
|
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2008-05-19 21:27:08 +09:00
|
|
|
if (!$user->update($original)) {
|
2008-07-08 18:45:31 +09:00
|
|
|
common_server_error(_('Can\'t save new password.'));
|
2008-05-16 01:28:44 +09:00
|
|
|
return;
|
|
|
|
}
|
2008-05-19 21:27:08 +09:00
|
|
|
|
2008-07-13 14:37:48 +09:00
|
|
|
$this->show_form(_('Password saved.'), true);
|
2008-05-16 01:28:44 +09:00
|
|
|
}
|
2008-07-01 02:03:42 +09:00
|
|
|
}
|