diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index f13bddc..3517c43 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -101,7 +101,7 @@ abstract class BaseController extends Controller helper('date'); $this->model = model('App\Models\SqlModel\BaseModelSql'); - $this->wablast = new DhivaProdevWa\ProdevMessages(ProdevToken); + // $this->wablast = new DhivaProdevWa\ProdevMessages(ProdevToken); $this->initControllers(); if (class_exists(\Config\ExternalApi::class)) { @@ -156,37 +156,27 @@ abstract class BaseController extends Controller { $bypassed = [ '/api/auth' => 'POST', - '/api/auth/v2' => 'POST', - '/api/user' => 'POST', - '/api/user-verifications/request-otp' => 'POST', - '/api/user-verifications/verification-otp-code' => 'POST', - '/api/user-verifications/resend-otp-code' => 'POST', - '/api/user-verifications/upload-face-photos' => 'POST', - '/api/forgot-password' => 'POST', - '/api/reset-password' => 'POST', - '/api/pelanggaran/feedback' => 'POST', - '/api/list-pelanggaran' => 'GET', - '/api/pelanggaran/get-feedback-by-id' => 'POST', - '/api/pencarian-pelanggaran-2' => 'POST', - '/api/check-bypass-liveness' => 'GET', - '/api/koperasi' => 'GET', - '/api/koperasi/' => 'GET', - '/api/get-distribusi-shu-mingguan/' => 'GET', - '/api/get-distribusi-shu-mingguan' => 'GET', - '/api/live-gold-price' => 'GET', - '/api/update-profile' => 'POST', - '/api/profile' => 'GET', - '/api/personel/profil' => 'GET', + '/api/personel/profil' => 'GET', // Allow profile access for QR ]; - $publickey = ''; - + $this->initHeader(); - $this->initDb('postgre', $publickey); + + // Try to connect to DB, but don't hang too long + try { + $this->initDb('postgre', ''); + } catch (\Exception $e) { + log_message('error', 'Database connection failed: ' . $e->getMessage()); + } - if ($this->checkEndpoint($this->getEndpointInfo(), $bypassed)) { + $endpointInfo = $this->getEndpointInfo(); + $cleanEndpoint = strtok($endpointInfo[1], '?'); + + // Check if bypassed + if (isset($bypassed[$cleanEndpoint]) && $bypassed[$cleanEndpoint] === $endpointInfo[0]) { return; } + // If not bypassed, require Authorization if (!isset($this->ClientSecret) || !isset($this->Authorization)) { $this->response(UNAUTHORIZED, 3); } @@ -202,15 +192,20 @@ abstract class BaseController extends Controller $this->response(UNAUTHORIZED, 3); } - // Update accessed_at time - $update['access_at'] = date('Y-m-d H:i:s', time()); $this->userDatas = $decodedToken; - $this->model->super_user->update($update, $decodedToken->super_user_id); - } catch (\Firebase\JWT\ExpiredException $e) { - log_message('error', 'Token expired: ' . $e->getMessage()); - $this->response(UNAUTHORIZED, 3); + + // Update accessed_at time - wrapped in try catch to prevent hang if update fails + try { + $update['access_at'] = date('Y-m-d H:i:s'); + $this->db->table('public.super_user') + ->where('super_user_id', $decodedToken->super_user_id) + ->update($update); + } catch (\Exception $e) { + // Ignore update error to keep the request alive + } + } catch (\Exception $e) { - log_message('error', 'Token validation error: ' . $e->getMessage()); + log_message('error', 'Auth validation error: ' . $e->getMessage()); $this->response(UNAUTHORIZED, 3); } } diff --git a/app/Controllers/SuperUserController.php b/app/Controllers/SuperUserController.php index 000ba2d..c002684 100644 --- a/app/Controllers/SuperUserController.php +++ b/app/Controllers/SuperUserController.php @@ -19,6 +19,9 @@ class SuperUserController extends BaseController */ public function auth() { + // Debug point + echo json_encode(["status" => "reached auth"]); die; + $inputUsername = $this->post('username'); $inputPassword = $this->post('password');