-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up the controllers, added in the module handling of the valid…
…ation errors.
- Loading branch information
1 parent
0156aa4
commit 3aaeb54
Showing
44 changed files
with
223 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @link https://github.com/monarc-project for the canonical source repository | ||
* @copyright Copyright (c) 2016-2023 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3 | ||
* @license MONARC is licensed under GNU Affero General Public License version 3 | ||
*/ | ||
|
||
namespace Monarc\BackOffice\Controller; | ||
|
||
use Laminas\Mvc\Controller\AbstractRestfulController; | ||
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; | ||
use Monarc\Core\Service\HistoricalService; | ||
|
||
class ApiAdminHistoricalController extends AbstractRestfulController | ||
{ | ||
use ControllerRequestResponseHandlerTrait; | ||
|
||
private HistoricalService $historicalService; | ||
|
||
public function __construct(HistoricalService $historicalService) | ||
{ | ||
$this->historicalService = $historicalService; | ||
} | ||
|
||
public function getList() | ||
{ | ||
$page = $this->params()->fromQuery('page'); | ||
$limit = $this->params()->fromQuery('limit'); | ||
$order = $this->params()->fromQuery('order'); | ||
$filter = $this->params()->fromQuery('filter'); | ||
|
||
return $this->getPreparedJsonResponse([ | ||
'count' => $this->historicalService->getFilteredCount($filter), | ||
'historical' => $this->historicalService->getList($page, $limit, $order, $filter) | ||
]); | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
/** | ||
* @link https://github.com/monarc-project for the canonical source repository | ||
* @copyright Copyright (c) 2016-2019 SMILE GIE Securitymadein.lu - Licensed under GNU Affero GPL v3 | ||
* @copyright Copyright (c) 2016-2023 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3 | ||
* @license MONARC is licensed under GNU Affero General Public License version 3 | ||
*/ | ||
|
||
namespace Monarc\BackOffice\Controller; | ||
|
||
use Exception; | ||
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; | ||
use Monarc\Core\Service\PasswordService; | ||
use Laminas\Mvc\Controller\AbstractRestfulController; | ||
use Laminas\View\Model\JsonModel; | ||
|
||
class ApiAdminPasswordsController extends AbstractRestfulController | ||
{ | ||
/** @var PasswordService */ | ||
private $passwordService; | ||
use ControllerRequestResponseHandlerTrait; | ||
|
||
private PasswordService $passwordService; | ||
|
||
public function __construct(PasswordService $passwordService) | ||
{ | ||
$this->passwordService = $passwordService; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function create($data) | ||
{ | ||
//password forgotten | ||
/* Password forgotten. */ | ||
if (!empty($data['email']) && empty($data['password'])) { | ||
try { | ||
$this->passwordService->passwordForgotten($data['email']); | ||
} catch (Exception $e) { | ||
// Ignore the exception: We don't want to leak any data | ||
throw new Exception('Password reset error occurred. Please try again later.', 422); | ||
} | ||
} | ||
|
||
//verify token | ||
/* Verify token. */ | ||
if (!empty($data['token']) && empty($data['password'])) { | ||
$result = $this->passwordService->verifyToken($data['token']); | ||
|
||
return new JsonModel(array('status' => $result)); | ||
return $this->getPreparedJsonResponse([ | ||
'status' => $this->passwordService->verifyToken($data['token']) | ||
]); | ||
} | ||
|
||
//change password not logged | ||
/* Change password, when user is not logged in. */ | ||
if (!empty($data['token']) && !empty($data['password']) && !empty($data['confirm'])) { | ||
if ($data['password'] !== $data['confirm']) { | ||
throw new Exception('Password must be the same', 422); | ||
throw new Exception('Password and its confirmation have to be equal.', 422); | ||
} | ||
|
||
$this->passwordService->newPasswordByToken($data['token'], $data['password']); | ||
} | ||
|
||
return new JsonModel(array('status' => 'ok')); | ||
return $this->getSuccessfulJsonResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.