Commit 52997ddd authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #16956 TIME 0:15 API to get OTP list from MP

parent afe53501
......@@ -641,6 +641,7 @@ $app->get('/messageExchangesInitialization', \MessageExchange\controllers\SendMe
//ExternalSignatoryBooks
$app->get('/documents/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getWorkflow');
$app->get('/maarchParapheurOtp', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getOtpList');
$app->get('/maarchParapheur/user/{id}/picture', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getUserPicture');
$app->get('/externalSignatureBooks/enabled', \ExternalSignatoryBook\controllers\ExternalSignatureBookController::class . ':getEnabledSignatureBook');
$app->get('/externalSummary/{resId}', \ExternalSummary\controllers\SummaryController::class . ':getByResId');
......
......@@ -1201,6 +1201,51 @@ class MaarchParapheurController
return $response->withJson($curlResponse['response']);
}
public function getOtpList(Request $request, Response $response, array $args)
{
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/visa/xml/remoteSignatoryBooks.xml']);
if (empty($loadedXml)) {
return $response->withStatus(400)->withJson(['errors' => 'SignatoryBooks configuration file missing']);
}
$url = '';
$userId = '';
$password = '';
foreach ($loadedXml->signatoryBook as $value) {
if ($value->id == "maarchParapheur") {
$url = rtrim($value->url, '/');
$userId = $value->userId;
$password = $value->password;
break;
}
}
if (empty($url)) {
return $response->withStatus(400)->withJson(['errors' => 'Maarch Parapheur configuration missing']);
}
$curlResponse = CurlModel::exec([
'url' => rtrim($url, '/') . "/rest/otp",
'basicAuth' => ['user' => $userId, 'password' => $password],
'headers' => ['content-type:application/json'],
'method' => 'GET'
]);
if ($curlResponse['code'] != '200') {
if (!empty($curlResponse['response']['errors'])) {
$errors = $curlResponse['response']['errors'];
} else {
$errors = $curlResponse['errors'];
}
if (empty($errors)) {
$errors = 'An error occured. Please check your configuration file.';
}
return $response->withStatus(400)->withJson(['errors' => $errors]);
}
return $response->withJson($curlResponse['response']);
}
public static function userExists($args)
{
ValidatorModel::notEmpty($args, ['userId']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment