CHANGE_JWT_TOKEN_IDEAL_TIME_SET : AADHAVAN
This commit is contained in:
parent
17bc0b9911
commit
f05c292b7c
@ -12,6 +12,7 @@ use ReflectionClass;
|
||||
|
||||
require_once('../vendor/autoload.php');
|
||||
|
||||
use App\Models\EmployeeModel;
|
||||
|
||||
|
||||
class AuthJWT implements FilterInterface
|
||||
@ -19,27 +20,27 @@ class AuthJWT implements FilterInterface
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
$jwt = $request->getHeader('Authorization');
|
||||
$model = new EmployeeModel();
|
||||
|
||||
if ($jwt) {
|
||||
if (JWTToken::validateJWT($jwt)) {
|
||||
$data = JWTToken::validateJWT($jwt);
|
||||
$data = json_decode($data);
|
||||
|
||||
$id = $data->decoded->id;
|
||||
$user_data = $model->where('id', $id)->first();
|
||||
|
||||
if ($data->status) {
|
||||
// $auth = $request->getHeader("Authorization");
|
||||
// $decodedToken = $data->decoded;
|
||||
|
||||
// $decodedToken->exp += 30;
|
||||
// $newJwt = JWTToken::encode((array)$decodedToken);
|
||||
|
||||
// Set the new JWT in the response headers
|
||||
// $response = service('response');
|
||||
// $response->setHeader('Authorization', $newJwt);
|
||||
if($user_data['token_time_out'] > time()){
|
||||
$data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ];
|
||||
$model->update($id, $data);
|
||||
return true;
|
||||
}else{
|
||||
$data =["token_time_out" => ''];
|
||||
$model->update($id, $data);
|
||||
header('Content-Type: application/json');
|
||||
http_response_code(401);
|
||||
$error = json_encode(["status" => 401, "message" => $data->message]);
|
||||
// $error = json_encode(["status" => 401, "message" => $data->message]);
|
||||
$error = json_encode(["status" => 401, "message" => "Token is Invalid"]);
|
||||
echo $error;
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -12,27 +12,28 @@ use Firebase\JWT\SignatureInvalidException;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use ReflectionClass;
|
||||
|
||||
use App\Models\EmployeeModel;
|
||||
|
||||
|
||||
class JWTToken
|
||||
{
|
||||
public static function encode($data =null)
|
||||
{
|
||||
$secret_Key="secret";
|
||||
$iat = time();
|
||||
$exp = $iat + 180;
|
||||
$request_data = [
|
||||
"iat" => $iat,
|
||||
"exp" => $exp,
|
||||
];
|
||||
if ($data !== null) {
|
||||
$request_data = array_merge($request_data, (array)$data);
|
||||
}
|
||||
try{
|
||||
$token = JWT::encode($request_data ,$secret_Key,'HS512');
|
||||
$secret_Key ="secret";
|
||||
|
||||
return $token;
|
||||
// return ['status' => true,'token' => $token];
|
||||
$request_data = (array)$data;
|
||||
|
||||
try{
|
||||
$token = JWT::encode($request_data ,$secret_Key,'HS512');
|
||||
|
||||
$model = new EmployeeModel();
|
||||
$id = $request_data['id'];
|
||||
$data =[
|
||||
"token_time_out" => time() + getenv('TOKENTIMEOUT')
|
||||
];
|
||||
$model->update($id, $data);
|
||||
|
||||
return $token;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
return ['status' => false,'message' => $e->getMessage()];
|
||||
|
||||
@ -38,7 +38,8 @@ class EmployeeModel extends Model
|
||||
"file_id",
|
||||
"is_addon_value",
|
||||
"is_createdby_hr",
|
||||
"client_branch_id"
|
||||
"client_branch_id",
|
||||
"token_time_out"
|
||||
];
|
||||
|
||||
// Callbacks
|
||||
|
||||
Loading…
Reference in New Issue
Block a user