back office login
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user