From 3628c4f2f20a11c9581cf552bb0857f4fd51c595 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Thu, 25 Apr 2024 11:28:58 -0400 Subject: [PATCH] back office login --- app/Config/Routes.php | 4 ++- app/Controllers/DigiFiAuth.php | 48 +++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 67b7760..b564e79 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -8,5 +8,7 @@ use CodeIgniter\Router\RouteCollection; $routes->get('/', 'Home::index'); -$routes->post('/digiusers/v1/identity/token', 'DigiFiAuth::starttoken'); +$routes->post('/digibko/v1/identity/token', 'DigiFiAuth::startBkoToken'); + + $routes->post('/digiusers/v1/identity/otoken', 'DigiFiAuth::starttoken'); diff --git a/app/Controllers/DigiFiAuth.php b/app/Controllers/DigiFiAuth.php index 37a60b6..7898d44 100644 --- a/app/Controllers/DigiFiAuth.php +++ b/app/Controllers/DigiFiAuth.php @@ -2,9 +2,13 @@ namespace App\Controllers; +use CodeIgniter\API\ResponseTrait; +use Firebase\JWT\JWT; class DigiFiAuth extends BaseController { + use ResponseTrait; + var $request; function __construct() { $this->request = \Config\Services::request(); @@ -14,11 +18,49 @@ class DigiFiAuth extends BaseController return ''; } - public function starttoken() + public function startBkoToken() { $data = $this->request->getPost(); - $final_out = $data; - return json_encode( $final_out ); + + if ( $data['username'] == 'demo@demo.com' && $data['pass']=== 'demo1' ){ + + $final_out = $data; + + $key = getenv('JWT_SECRET'); + $iat = time(); // current timestamp value + $exp = $iat + 3600; + + $payload = array( + "iss" => "Issuer of the JWT", + "aud" => "Audience that the JWT", + "sub" => "Subject of the JWT", + "iat" => $iat, //Time the JWT issued at + "exp" => $exp, // Expiration time of token + "user_detail" =>$final_out, + ); + + $token = JWT::encode($payload, $key, 'HS256'); + + $response = [ + 'message' => 'Login was successful', + 'call_return' => '100', + 'token' => $token + ]; + + return $this->respond($response, 200); + } + else{ + $response = [ + 'message' => 'Login failed', + 'call_return' => '100', + 'token' => '' + ]; + return $this->fail($response , 409); + } + + + + //return json_encode( $response ); } }