2008-05-15 17:28:44 +01:00
|
|
|
<?php
|
2008-05-19 13:27:08 +01:00
|
|
|
/*
|
2008-05-15 17:28:44 +01:00
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
2008-05-19 13:27:08 +01:00
|
|
|
*
|
2008-05-15 17:28:44 +01: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 13:27:08 +01:00
|
|
|
*
|
2008-05-15 17:28:44 +01: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 13:27:08 +01:00
|
|
|
*
|
2008-05-15 17:28:44 +01: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-17 16:47:01 +01:00
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
2008-05-15 17:28:44 +01:00
|
|
|
|
2008-05-17 18:54:16 +01:00
|
|
|
require_once(INSTALLDIR.'/lib/settingsaction.php');
|
|
|
|
|
2008-05-15 17:28:44 +01:00
|
|
|
class PasswordAction extends SettingsAction {
|
2008-05-19 13:27:08 +01:00
|
|
|
|
2008-06-30 18:03:42 +01:00
|
|
|
function get_instructions() {
|
2008-07-08 10:45:31 +01:00
|
|
|
return _('You can change your password here. Choose a good one!');
|
2008-06-18 04:57:39 +01:00
|
|
|
}
|
2008-06-30 18:03:42 +01:00
|
|
|
|
2008-06-18 04:57:39 +01:00
|
|
|
function show_form($msg=NULL, $success=false) {
|
2008-07-08 05:12:10 +01:00
|
|
|
$user = common_current_user();
|
2008-07-08 10:45:31 +01:00
|
|
|
$this->form_header(_('Change password'), $msg, $success);
|
2008-08-29 02:45:15 +01:00
|
|
|
$token = common_session_token();
|
2008-07-02 14:15:07 +01:00
|
|
|
common_element_start('form', array('method' => 'post',
|
2008-05-15 17:28:44 +01:00
|
|
|
'id' => 'password',
|
2008-05-19 13:27:08 +01:00
|
|
|
'action' =>
|
2008-05-15 17:28:44 +01:00
|
|
|
common_local_url('password')));
|
2008-08-29 02:45:15 +01:00
|
|
|
common_hidden('token', $token);
|
2008-07-08 05:12:10 +01:00
|
|
|
# Users who logged in with OpenID won't have a pwd
|
|
|
|
if ($user->password) {
|
2008-07-08 10:45:31 +01:00
|
|
|
common_password('oldpassword', _('Old password'));
|
2008-07-08 05:12:10 +01:00
|
|
|
}
|
2008-07-08 10:45:31 +01:00
|
|
|
common_password('newpassword', _('New password'),
|
|
|
|
_('6 or more characters'));
|
|
|
|
common_password('confirm', _('Confirm'),
|
|
|
|
_('same as password above'));
|
|
|
|
common_submit('submit', _('Change'));
|
2008-05-17 18:04:30 +01:00
|
|
|
common_element_end('form');
|
2008-05-19 14:21:18 +01:00
|
|
|
common_show_footer();
|
2008-05-15 17:28:44 +01:00
|
|
|
}
|
2008-05-19 13:27:08 +01:00
|
|
|
|
2008-05-15 17:28:44 +01:00
|
|
|
function handle_post() {
|
|
|
|
|
|
|
|
$user = common_current_user();
|
|
|
|
assert(!is_null($user)); # should already be checked
|
2008-05-19 13:27:08 +01:00
|
|
|
|
2008-05-15 17:28:44 +01:00
|
|
|
# FIXME: scrub input
|
|
|
|
|
|
|
|
$newpassword = $this->arg('newpassword');
|
|
|
|
$confirm = $this->arg('confirm');
|
2008-08-29 02:45:15 +01: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.'));
|
|
|
|
} else if (0 != strcmp($newpassword, $confirm)) {
|
2008-07-13 06:37:48 +01:00
|
|
|
$this->show_form(_('Passwords don\'t match.'));
|
2008-05-15 17:28:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-08 05:12:10 +01:00
|
|
|
if ($user->password) {
|
|
|
|
$oldpassword = $this->arg('oldpassword');
|
2008-07-08 10:45:31 +01:00
|
|
|
|
2008-07-08 05:12:10 +01:00
|
|
|
if (!common_check_user($user->nickname, $oldpassword)) {
|
2008-07-08 10:45:31 +01:00
|
|
|
$this->show_form(_('Incorrect old password'));
|
2008-07-08 05:12:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-05-15 17:28:44 +01:00
|
|
|
}
|
2008-05-19 13:27:08 +01:00
|
|
|
|
|
|
|
$original = clone($user);
|
|
|
|
|
2008-05-15 17:28:44 +01:00
|
|
|
$user->password = common_munge_password($newpassword, $user->id);
|
2008-05-19 13:27:08 +01:00
|
|
|
|
2008-05-20 20:10:32 +01:00
|
|
|
$val = $user->validate();
|
|
|
|
if ($val !== TRUE) {
|
2008-07-08 10:45:31 +01:00
|
|
|
$this->show_form(_('Error saving user; invalid.'));
|
2008-05-20 20:10:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-05-20 20:14:12 +01:00
|
|
|
|
2008-05-19 13:27:08 +01:00
|
|
|
if (!$user->update($original)) {
|
2008-07-08 10:45:31 +01:00
|
|
|
common_server_error(_('Can\'t save new password.'));
|
2008-05-15 17:28:44 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-05-19 13:27:08 +01:00
|
|
|
|
2008-07-13 06:37:48 +01:00
|
|
|
$this->show_form(_('Password saved.'), true);
|
2008-05-15 17:28:44 +01:00
|
|
|
}
|
2008-06-30 18:03:42 +01:00
|
|
|
}
|