getHeader('Authorization'); if ($jwt) { if (JWTToken::validateJWT($jwt)) { $data = JWTToken::validateJWT($jwt); $data = json_decode($data); $id = $data->decoded->id; if(isset($data->decoded->emp_code)){ $model = new EmployeeModel(); $user_data = $model->where('id', $id)->first(); if($user_data['token_time_out'] > time()){ $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; $model->update($id, $data); return true; }else{ // if($user_data['token_time_out'] != "" && $user_data['token_time_out'] != NULL) $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" => "Token is Invalid"]); echo $error; exit; } }else{ $model = new LevelContactModel(); $hr_data = $model->where('id', $id)->first(); if($hr_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" => "Token is Invalid"]); echo $error; exit; } } } } else { header('Content-Type: application/json'); http_response_code(403); $error = json_encode(["status" => 403, "message" => "Access Forbidden!"]); echo $error; exit(); } } public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { // Do something here after the response is sent } }