- move elixForms API logic to specific folder - move everything else under Api folder
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
namespace Api\Controllers;
|
|
|
|
use Core\Request;
|
|
use Core\Response;
|
|
use ElixForms\ElixFormsClient;
|
|
use ElixForms\Exceptions\ElixFormsException;
|
|
|
|
class ExternalElixFormsController
|
|
{
|
|
private ElixFormsClient $elixFormsClient;
|
|
|
|
public function __construct(ElixFormsClient $elixFormsClient)
|
|
{
|
|
$this->elixFormsClient = $elixFormsClient;
|
|
}
|
|
|
|
public function status(Request $req, Response $res)
|
|
{
|
|
try {
|
|
$response = $this->elixFormsClient->request('GET', '/status');
|
|
return $res->json([
|
|
'status' => $response['status'],
|
|
'body' => $response['json'] ?? $response['body']
|
|
]);
|
|
} catch (ElixFormsException $e) {
|
|
return $res->json(['error' => $e->getMessage()], 500);
|
|
}
|
|
}
|
|
|
|
public function login(Request $req, Response $res)
|
|
{
|
|
$data = $req->body();
|
|
$username = $data['username'] ?? '';
|
|
$password = $data['password'] ?? '';
|
|
|
|
try {
|
|
$token = $this->elixFormsClient->auth()->login($username, $password);
|
|
return $res->json(['authToken' => $token]);
|
|
} catch (ElixFormsException $e) {
|
|
return $res->json(['error' => $e->getMessage()], 401);
|
|
}
|
|
}
|
|
}
|