diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 08fcb2b..8ef525f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -439,6 +439,8 @@ $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMail $routes->cli('cli/app_check_list', 'MasterController::appCheckList'); $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken'); $routes->cli('cli/check_env', 'MasterController::checkEnv'); +$routes->cli('cli/reset-token-timeout', 'RestAuthenticationController::resetTokenTimeOut'); +$routes->cli('cli/reset-token-timeout/(:num)', 'RestAuthenticationController::resetTokenTimeOut/$1'); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index aecf3a0..d81da1a 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -1962,6 +1962,11 @@ class RestAuthenticationController extends AdminController public function logout() { + return $this->respond([ + 'status' => true, + 'message' => 'Logged out successfully' + ], 200); + $authHeader = $this->request->getHeaderLine('Authorization'); if (!$authHeader) { @@ -2009,5 +2014,54 @@ class RestAuthenticationController extends AdminController ], 200); } + + public function resetTokenTimeOut($bufferSeconds = null) + { + if (!is_cli()) { + return $this->respond([ + 'status' => false, + 'message' => 'This endpoint is CLI only.' + ], 403); + } + + $envBuffer = (int) (getenv('TOKEN_TIMEOUT_RESET_BUFFER_SECONDS') ?: 300); + $buffer = is_numeric($bufferSeconds) ? (int) $bufferSeconds : $envBuffer; + if ($buffer < 0) { + $buffer = 0; + } + + $cutoffEpoch = time() - $buffer; + $db = db_connect(); + + $db->table('level_contacts') + ->where('token_time_out IS NOT NULL', null, false) + ->where('token_time_out <=', $cutoffEpoch) + ->set(['token_time_out' => null]) + ->update(); + $levelContactsUpdated = $db->affectedRows(); + + $db->table('employees') + ->where('token_time_out IS NOT NULL', null, false) + ->where('token_time_out <=', $cutoffEpoch) + ->set(['token_time_out' => null]) + ->update(); + $employeesUpdated = $db->affectedRows(); + + $result = [ + 'status' => true, + 'message' => 'Token timeout reset completed.', + 'buffer_seconds' => $buffer, + 'cutoff_epoch' => $cutoffEpoch, + 'updated' => [ + 'level_contacts' => $levelContactsUpdated, + 'employees' => $employeesUpdated, + 'total' => $levelContactsUpdated + $employeesUpdated, + ], + ]; + + echo json_encode($result, JSON_UNESCAPED_SLASHES) . PHP_EOL; + return; + } + }