|
|
@@ -3,8 +3,10 @@
|
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
|
|
use FrameworkX\App;
|
|
|
+use Libs\ResponseLib;
|
|
|
use Middlewares\CorsMiddleware;
|
|
|
use Middlewares\JwtAuthMiddleware;
|
|
|
+use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
|
$requestUri = $_SERVER['REQUEST_URI'] ?? null;
|
|
|
$path = $requestUri !== null ? parse_url($requestUri, PHP_URL_PATH) : '/';
|
|
|
@@ -40,10 +42,20 @@ $globalMiddleware = $corsEnabled ? [CorsMiddleware::class] : [];
|
|
|
$app = new App(...$globalMiddleware);
|
|
|
$authJwt = new JwtAuthMiddleware();
|
|
|
|
|
|
+$onlyCompany1Or2 = function (ServerRequestInterface $request, callable $next) {
|
|
|
+ $companyId = (int)($request->getAttribute('api_company_id') ?? 0);
|
|
|
+ if ($companyId !== 1 && $companyId !== 2) {
|
|
|
+ return ResponseLib::sendFail('Forbidden', [], 'E_FORBIDDEN')->withStatus(403);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $next($request);
|
|
|
+};
|
|
|
+
|
|
|
$app->post('/verify/jwt', $authJwt,\Controllers\HelloController::class);
|
|
|
|
|
|
$app->post('/login', \Controllers\LoginController::class);
|
|
|
$app->post('/register', $authJwt, \Controllers\RegisterController::class);
|
|
|
+$app->post('/auth/superadmin', $authJwt, \Controllers\SuperAdminGetController::class);
|
|
|
$app->post('/user/get', $authJwt, \Controllers\UserGetController::class);
|
|
|
$app->post('/user/info', $authJwt, \Controllers\UserInfoController::class);
|
|
|
$app->post('/user/delete', $authJwt, \Controllers\UserDeleteController::class);
|
|
|
@@ -79,8 +91,12 @@ $app->post('/orderbook/cancel', $authJwt, \Controllers\OrderbookUpdateStatusCont
|
|
|
$app->post('/orderbook/transfer', $authJwt, \Controllers\OrderbookTransferController::class);
|
|
|
$app->post('/harvest/list', $authJwt, \Controllers\HarvestListController::class);
|
|
|
|
|
|
+$app->post('/discount/get', $authJwt, $onlyCompany1Or2, \Controllers\DiscountGetController::class);
|
|
|
+$app->post('/discount/create', $authJwt, $onlyCompany1Or2, \Controllers\DiscountCreateController::class);
|
|
|
+$app->post('/discount/delete', $authJwt, $onlyCompany1Or2, \Controllers\DiscountDeleteController::class);
|
|
|
+
|
|
|
$app->post('/b3/token', \Controllers\B3TokenController::class);
|
|
|
-$app->post('/b3/cpr/register', $authJwt, \Controllers\B3CprRegisterController::class);
|
|
|
+$app->post('/b3/cpr/register', $authJwt, $onlyCompany1Or2, \Controllers\B3CprRegisterController::class);
|
|
|
$app->post('/b3/payment/confirm', $authJwt, \Controllers\PaymentConfirmController::class);
|
|
|
$app->post('/cpr/fast-track', \Controllers\CprFastTrackController::class);
|
|
|
|