diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 09012fc..8450de0 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -22,7 +22,6 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { // Login api $routes->post('auth/login', 'AuthController::login'); - $routes->get('auth/logout', 'AuthController::logout'); $routes->get('auth/oauthClient', 'AuthController::oauthClient'); $routes->post('auth/oauthlogin', 'AuthController::oauthlogin'); @@ -44,6 +43,10 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->group('api', ['filter' => ["jwtAuth:Org Admin,Travel Admin,Travel Agent,User","appSignature"] ], function ($routes) { + $routes->get('auth/logout', 'AuthController::logout'); + + $routes->get('downloadPassport', 'UserController::downloadPassport'); + $routes->get('organizations/find/(:num)', 'OrganizationController::find/$1'); // Org admin, Travel admin, Travel agent,user $routes->get('users/find/(:num)', 'UserController::find/$1'); // Org admin, Travel admin, Travel agent,user $routes->post('plans/createOrEditPlan', 'PlanController::createOrEditPlan'); // Org admin, Travel admin, Travel agent,user diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php index a395bf2..dd5ddea 100644 --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -411,10 +411,41 @@ class AuthController extends ResourceController public function logout() { $user_id = $this->request->getGet('user_id'); + $headerToken = $this->request->getHeaderLine('Authorization'); // Get the full header + + // Remove "Bearer " prefix if present + $token = null; + if (!empty($headerToken)) { + $token = str_replace('Bearer ', '', $headerToken); + } + + // Validate user existence and active status + $user = $this->userModel->where('user_id', $user_id)->where('is_active', 1)->first(); + + if (!$user) { + return $this->respond([ + 'status' => 400, + 'message' => 'User not found or inactive' + ], 400); + } + + // Check token match + if ($user['current_token'] !== $token) { + return $this->respond([ + 'status' => 401, + 'message' => 'Unknown login or invalid token' + ], 401); + } + + // Token matches — logout success $this->userModel->update($user_id, ['current_token' => null]); - - return $this->respond(['message' => 'Logout successful']); + + return $this->respond([ + 'status' => 200, + 'message' => 'Logout successful' + ], 200); } + diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 50596b9..7f92580 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -871,6 +871,43 @@ public function userUploadTemplate() } +public function downloadPassport() +{ + $user_id = $this->request->getGet('user_id'); + + + + // Get user data + $user = $this->userModel->select('passport_document')->where('user_id', $user_id)->first(); + + if (!$user || empty($user['passport_document'])) { + return $this->respond([ + 'status' => 404, + 'message' => 'Passport document not found' + ], 404); + } + + // Full path from DB + $filePath = $user['passport_document']; + + // If file path stored includes domain or base path, extract only the actual file path + // Example: /home3/venbaehn/apitest.tripapprovaltool.com/tstat_be/assets/images/passport/filename.pdf + if (!file_exists($filePath)) { + return $this->respond([ + 'status' => 404, + 'message' => 'File not found on server' + ], 404); + } + + // Extract just the filename (for download name) + $fileName = basename($filePath); + + // Return file as downloadable response + return $this->response->download($filePath, null)->setFileName($fileName); +} + + +