2005-07-23 11:44:46 +02:00
|
|
|
<?php
|
2010-07-27 16:29:20 +02:00
|
|
|
/**
|
|
|
|
* EGroupware preferences
|
|
|
|
*
|
|
|
|
* @package preferences
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Joseph Engo <jengo@phpgroupware.org>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2014-04-17 09:37:21 +02:00
|
|
|
class preferences_password
|
2010-07-27 16:29:20 +02:00
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'change' => True
|
|
|
|
);
|
|
|
|
|
2015-03-12 17:58:01 +01:00
|
|
|
/**
|
|
|
|
* Change password function
|
|
|
|
* process change password form
|
|
|
|
*
|
|
|
|
* @param type $content
|
|
|
|
*/
|
|
|
|
function change($content = null)
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
2015-03-12 17:58:01 +01:00
|
|
|
if ($GLOBALS['egw']->acl->check('nopasswordchange', 1))
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
2015-03-12 17:58:01 +01:00
|
|
|
egw_framework::window_close('There was no password change!');
|
2010-07-27 16:29:20 +02:00
|
|
|
}
|
2015-07-01 19:54:18 +02:00
|
|
|
|
2015-03-12 17:58:01 +01:00
|
|
|
if (!is_array($content))
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
2015-03-12 17:58:01 +01:00
|
|
|
$content= array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($content['button']['change'])
|
2005-07-23 11:44:46 +02:00
|
|
|
{
|
2015-07-01 19:54:18 +02:00
|
|
|
if (($errors = self::do_change($content['o_passwd_2'], $content['n_passwd'], $content['n_passwd_2'])))
|
2015-03-12 17:58:01 +01:00
|
|
|
{
|
|
|
|
egw_framework::message(implode("\n", $errors), 'error');
|
|
|
|
$content = array();
|
2013-07-14 15:05:24 +02:00
|
|
|
}
|
2015-03-12 17:58:01 +01:00
|
|
|
else
|
2013-06-23 12:46:26 +02:00
|
|
|
{
|
2015-03-12 17:58:01 +01:00
|
|
|
egw_framework::refresh_opener(lang('Password changed'), 'preferences');
|
|
|
|
egw_framework::window_close();
|
2013-06-23 12:46:26 +02:00
|
|
|
}
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-12 17:58:01 +01:00
|
|
|
|
2010-07-27 16:29:20 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Change your password');
|
2015-03-12 17:58:01 +01:00
|
|
|
$tmpl = new etemplate_new('preferences.password');
|
2010-07-27 16:29:20 +02:00
|
|
|
|
2015-03-12 17:58:01 +01:00
|
|
|
$tmpl->exec('preferences.preferences_password.change', $content,array(),array(),array(),2);
|
2005-07-23 11:44:46 +02:00
|
|
|
}
|
2015-07-01 19:54:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do some basic checks and then change password
|
|
|
|
*
|
|
|
|
* @param string $old_passwd
|
|
|
|
* @param string $new_passwd
|
|
|
|
* @param string $new_passwd2
|
|
|
|
* @return array with already translated errors
|
|
|
|
*/
|
|
|
|
public static function do_change($old_passwd, $new_passwd, $new_passwd2)
|
|
|
|
{
|
|
|
|
if ($GLOBALS['egw_info']['flags']['currentapp'] != 'preferences')
|
|
|
|
{
|
|
|
|
translation::add_app('preferences');
|
|
|
|
}
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if (isset($GLOBALS['egw_info']['user']['passwd']) &&
|
|
|
|
$old_passwd !== $GLOBALS['egw_info']['user']['passwd'])
|
|
|
|
{
|
|
|
|
$errors[] = lang('The old password is not correct');
|
|
|
|
}
|
|
|
|
if ($new_passwd != $new_passwd2)
|
|
|
|
{
|
|
|
|
$errors[] = lang('The two passwords are not the same');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($old_passwd !== false && $old_passwd == $new_passwd)
|
|
|
|
{
|
|
|
|
$errors[] = lang('Old password and new password are the same. This is invalid. You must enter a new password');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$new_passwd)
|
|
|
|
{
|
|
|
|
$errors[] = lang('You must enter a password');
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow auth backends or configured password strenght to throw exceptions and display there message
|
|
|
|
if (!$errors)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (!$GLOBALS['egw']->auth->change_password($old_passwd, $new_passwd,
|
|
|
|
$GLOBALS['egw']->session->account_id))
|
|
|
|
{
|
|
|
|
// if we have no specific error, add general message
|
|
|
|
$errors[] = lang('Failed to change password.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$errors[] = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
2010-07-27 16:29:20 +02:00
|
|
|
}
|