2007-11-27 04:20:28 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2016-04-27 21:12:20 +02:00
|
|
|
* EGgroupware admin - admin command: change the password of a given user
|
2007-11-27 04:20:28 +01:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package admin
|
2016-04-27 21:12:20 +02:00
|
|
|
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-11-27 04:20:28 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2013-10-25 21:24:01 +02:00
|
|
|
* @version $Id$
|
2007-11-27 04:20:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2007-11-27 04:20:28 +01:00
|
|
|
/**
|
|
|
|
* admin command: change the password of a given user
|
|
|
|
*/
|
2013-10-25 21:24:01 +02:00
|
|
|
class admin_cmd_change_pw extends admin_cmd
|
2007-11-27 04:20:28 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2016-04-27 21:12:20 +02:00
|
|
|
* @param string|int|array $account account name or id, or array with all parameters
|
|
|
|
* @param string $password =null password
|
2007-11-27 04:20:28 +01:00
|
|
|
*/
|
|
|
|
function __construct($account,$password=null)
|
|
|
|
{
|
|
|
|
if (!is_array($account))
|
|
|
|
{
|
|
|
|
$account = array(
|
|
|
|
'account' => $account,
|
|
|
|
'password' => $password,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
admin_cmd::__construct($account);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* change the password of a given user
|
2013-10-25 21:24:01 +02:00
|
|
|
*
|
2016-04-27 21:12:20 +02:00
|
|
|
* @param boolean $check_only =false only run the checks (and throw the exceptions), but not the command itself
|
2007-11-27 04:20:28 +01:00
|
|
|
* @return string success message
|
2016-04-27 21:12:20 +02:00
|
|
|
* @throws Api\Exception\NoPermission\Admin
|
|
|
|
* @throws Api\Exception\WrongUserinput(lang("Unknown account: %1 !!!",$this->account),15);
|
|
|
|
* @throws Api\Exception\WrongUserinput(lang('Error changing the password for %1 !!!',$this->account),99);
|
2007-11-27 04:20:28 +01:00
|
|
|
*/
|
|
|
|
protected function exec($check_only=false)
|
|
|
|
{
|
2019-03-20 22:36:20 +01:00
|
|
|
$this->account = admin_cmd::parse_account($this->account,true); // true = user, no group
|
2016-04-27 21:12:20 +02:00
|
|
|
// check creator is still admin and not explicitly forbidden to edit Api\Accounts
|
2007-11-27 04:20:28 +01:00
|
|
|
if ($this->creator) $this->_check_admin('account_access',16);
|
2013-10-25 21:24:01 +02:00
|
|
|
|
2007-11-27 04:20:28 +01:00
|
|
|
if ($check_only) return true;
|
2013-10-25 21:24:01 +02:00
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
$auth = new Api\Auth;
|
2013-10-25 21:24:01 +02:00
|
|
|
|
2019-03-20 22:36:20 +01:00
|
|
|
if (!$auth->change_password(null, $this->password, $this->account))
|
2007-11-27 04:20:28 +01:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
// as long as the Api\Auth class is not throwing itself ...
|
2014-06-18 10:03:13 +02:00
|
|
|
throw new Exception(lang('Error changing the password for %1 !!!',$this->account),99);
|
2007-11-27 04:20:28 +01:00
|
|
|
}
|
|
|
|
return lang('Password updated');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a title / string representation for a given command, eg. to display it
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function __tostring()
|
|
|
|
{
|
|
|
|
return lang('change password for %1',admin_cmd::display_account($this->account));
|
|
|
|
}
|
|
|
|
}
|