120 lines
2.9 KiB
PHP
120 lines
2.9 KiB
PHP
<?php
|
|
|
|
// declare(strict_types=1);
|
|
|
|
|
|
namespace App\Controllers;
|
|
use App\Helpers\DepositHelper;
|
|
use App\Helpers\JWTToken;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
|
|
use App\Models\EmployeeModel;
|
|
|
|
|
|
use Firebase\JWT\JWT;
|
|
// require_once('../vendor/autoload.php');
|
|
|
|
|
|
|
|
class RestAuthenticationController extends AdminController
|
|
{
|
|
use ResponseTrait;
|
|
|
|
protected $myLogger;
|
|
protected $employeeModel;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
// set_session_context('Client');
|
|
$this->myLogger = \Config\Services::mylogger();
|
|
|
|
$this->employeeModel = new EmployeeModel();
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->myLogger->logme('error','Rest Authentication function called');
|
|
$data =["id"=>"2", "role"=>"staff"];
|
|
|
|
print_r(JWTToken::encode($data));
|
|
}
|
|
|
|
public function logined()
|
|
{
|
|
|
|
$this->myLogger->logme('error','Rest Authentication function called');
|
|
|
|
echo "Rest Authentication Logined Success........";
|
|
}
|
|
|
|
|
|
public function verifyEmployeeWithMobileNumber()
|
|
{
|
|
try {
|
|
$mobile_number = $this->request->getJSON()->mobile_number;
|
|
|
|
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->first();
|
|
if ($employeeData) {
|
|
$result = ['user_verification' => true];
|
|
return ['status' => 'success','code' => 200,'data' => $result];
|
|
} else {
|
|
$result = ['user_verification' => false];
|
|
return ['status' => 'failed','code' => 404,'data' => $result];
|
|
}
|
|
} catch (\Throwable $th) {
|
|
return ['status' => 'failed','code' => 505,'data' => $th];
|
|
}
|
|
}
|
|
|
|
|
|
public function getVerifiedUserData()
|
|
{
|
|
try {
|
|
$mobile_number = $this->request->getJSON()->mobile_number;
|
|
|
|
$employeeData = $this->employeeModel->where('mobile', $mobile_number)->first();
|
|
if ($employeeData) {
|
|
$result = JWTToken::encode($employeeData);
|
|
return ['status' => 'success','code' => 200,'data' => $result];
|
|
} else {
|
|
return ['status' => 'failed','code' => 404,'data' => "No data"];
|
|
}
|
|
} catch (\Throwable $th) {
|
|
return ['status' => 'failed','code' => 500,'data' => $th];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function employeeLogout()
|
|
{
|
|
|
|
}
|
|
|
|
public function getUserIdFromToken()
|
|
{
|
|
$id = JWTToken::getUserIdFromToken();
|
|
// echo $id['id'];
|
|
echo "Id----> ";
|
|
print_r($id);
|
|
$role = JWTToken::getUserRoleFromToken();
|
|
echo " Role----> ";
|
|
echo $role;
|
|
|
|
|
|
$tokenArray = JWTToken::decodeToken();
|
|
echo " TokenArray----> ";
|
|
print_r($tokenArray);
|
|
}
|
|
|
|
|
|
|
|
} |