make Customers::update() also work with loginname as an alternative to the id
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -95,7 +95,7 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
* delete a admin entry by either id or loginname
|
* delete a admin entry by either id or loginname
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* optional, the customer-id
|
* optional, the admin-id
|
||||||
* @param string $loginname
|
* @param string $loginname
|
||||||
* optional, the loginname
|
* optional, the loginname
|
||||||
* @param bool $delete_userfiles
|
* @param bool $delete_userfiles
|
||||||
@@ -109,15 +109,46 @@ class Admins extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unlock a locked admin by id
|
* unlock a locked admin by either id or loginname
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* customer-id
|
* optional, the admin-id
|
||||||
|
* @param string $loginname
|
||||||
|
* optional, the loginname
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function unlock()
|
public function unlock()
|
||||||
{
|
{
|
||||||
|
if ($this->isAdmin()) {
|
||||||
|
$id = $this->getParam('id', true, 0);
|
||||||
|
$ln_optional = ($id <= 0 ? false : true);
|
||||||
|
$loginname = $this->getParam('loginname', $ln_optional, '');
|
||||||
|
|
||||||
|
if ($id <= 0 && empty($loginname)) {
|
||||||
|
throw new Exception("Either 'id' or 'loginname' parameter must be given", 406);
|
||||||
|
}
|
||||||
|
|
||||||
|
$json_result = Admins::getLocal($this->getUserData(), array(
|
||||||
|
'id' => $id,
|
||||||
|
'loginname' => $loginname
|
||||||
|
))->get();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$id = $result['adminid'];
|
||||||
|
|
||||||
|
$result_stmt = Database::prepare("
|
||||||
|
UPDATE `" . TABLE_PANEL_ADMINS . "` SET
|
||||||
|
`loginfail_count` = '0'
|
||||||
|
WHERE `adminid`= :id
|
||||||
|
");
|
||||||
|
Database::pexecute($result_stmt, array(
|
||||||
|
'id' => $id
|
||||||
|
), true, true);
|
||||||
|
|
||||||
|
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] unlocked admin '" . $result['loginname'] . "'");
|
||||||
|
return $this->response(200, "successfull", $result);
|
||||||
|
}
|
||||||
|
throw new Exception("Not allowed to execute given command.", 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -646,12 +646,20 @@ class Customers extends ApiCommand implements ResourceEntity
|
|||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
if ($this->isAdmin()) {
|
if ($this->isAdmin()) {
|
||||||
$id = $this->getParam('id');
|
$id = $this->getParam('id', true, 0);
|
||||||
|
$ln_optional = ($id <= 0 ? false : true);
|
||||||
|
$loginname = $this->getParam('loginname', $ln_optional, '');
|
||||||
|
|
||||||
|
if ($id <= 0 && empty($loginname)) {
|
||||||
|
throw new Exception("Either 'id' or 'loginname' parameter must be given", 406);
|
||||||
|
}
|
||||||
|
|
||||||
$json_result = Customers::getLocal($this->getUserData(), array(
|
$json_result = Customers::getLocal($this->getUserData(), array(
|
||||||
'id' => $id
|
'id' => $id,
|
||||||
|
'loginname' => $loginname
|
||||||
))->get();
|
))->get();
|
||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$id = $result['customerid'];
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
$move_to_admin = intval_ressource($this->getParam('move_to_admin', true, 0));
|
$move_to_admin = intval_ressource($this->getParam('move_to_admin', true, 0));
|
||||||
@@ -1354,10 +1362,12 @@ class Customers extends ApiCommand implements ResourceEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unlock a locked customer by id
|
* unlock a locked customer by either id or loginname
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* customer-id
|
* optional, the customer-id
|
||||||
|
* @param string $loginname
|
||||||
|
* optional, the loginname
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @return array
|
* @return array
|
||||||
@@ -1365,12 +1375,20 @@ class Customers extends ApiCommand implements ResourceEntity
|
|||||||
public function unlock()
|
public function unlock()
|
||||||
{
|
{
|
||||||
if ($this->isAdmin()) {
|
if ($this->isAdmin()) {
|
||||||
$id = $this->getParam('id');
|
$id = $this->getParam('id', true, 0);
|
||||||
|
$ln_optional = ($id <= 0 ? false : true);
|
||||||
|
$loginname = $this->getParam('loginname', $ln_optional, '');
|
||||||
|
|
||||||
|
if ($id <= 0 && empty($loginname)) {
|
||||||
|
throw new Exception("Either 'id' or 'loginname' parameter must be given", 406);
|
||||||
|
}
|
||||||
|
|
||||||
$json_result = Customers::getLocal($this->getUserData(), array(
|
$json_result = Customers::getLocal($this->getUserData(), array(
|
||||||
'id' => $id
|
'id' => $id,
|
||||||
|
'loginname' => $loginname
|
||||||
))->get();
|
))->get();
|
||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$id = $result['customerid'];
|
||||||
|
|
||||||
$result_stmt = Database::prepare("
|
$result_stmt = Database::prepare("
|
||||||
UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET
|
UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET
|
||||||
|
|||||||
Reference in New Issue
Block a user