GWM : logout api and passport download api

This commit is contained in:
Gowtham M 2025-10-08 12:26:36 +05:30
parent 15198ed89c
commit 6f37f65968
3 changed files with 74 additions and 3 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}