Merge branch 'master' of git.adhivasindo.co.id:naden/API-KTA

This commit is contained in:
Naden
2026-04-25 05:23:50 +07:00
2 changed files with 31 additions and 33 deletions

View File

@@ -101,7 +101,7 @@ abstract class BaseController extends Controller
helper('date'); helper('date');
$this->model = model('App\Models\SqlModel\BaseModelSql'); $this->model = model('App\Models\SqlModel\BaseModelSql');
$this->wablast = new DhivaProdevWa\ProdevMessages(ProdevToken); // $this->wablast = new DhivaProdevWa\ProdevMessages(ProdevToken);
$this->initControllers(); $this->initControllers();
if (class_exists(\Config\ExternalApi::class)) { if (class_exists(\Config\ExternalApi::class)) {
@@ -156,37 +156,27 @@ abstract class BaseController extends Controller
{ {
$bypassed = [ $bypassed = [
'/api/auth' => 'POST', '/api/auth' => 'POST',
'/api/auth/v2' => 'POST', '/api/personel/profil' => 'GET', // Allow profile access for QR
'/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',
]; ];
$publickey = '';
$this->initHeader(); $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; return;
} }
// If not bypassed, require Authorization
if (!isset($this->ClientSecret) || !isset($this->Authorization)) { if (!isset($this->ClientSecret) || !isset($this->Authorization)) {
$this->response(UNAUTHORIZED, 3); $this->response(UNAUTHORIZED, 3);
} }
@@ -202,15 +192,20 @@ abstract class BaseController extends Controller
$this->response(UNAUTHORIZED, 3); $this->response(UNAUTHORIZED, 3);
} }
// Update accessed_at time
$update['access_at'] = date('Y-m-d H:i:s', time());
$this->userDatas = $decodedToken; $this->userDatas = $decodedToken;
$this->model->super_user->update($update, $decodedToken->super_user_id);
} catch (\Firebase\JWT\ExpiredException $e) { // Update accessed_at time - wrapped in try catch to prevent hang if update fails
log_message('error', 'Token expired: ' . $e->getMessage()); try {
$this->response(UNAUTHORIZED, 3); $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) { } catch (\Exception $e) {
log_message('error', 'Token validation error: ' . $e->getMessage()); log_message('error', 'Auth validation error: ' . $e->getMessage());
$this->response(UNAUTHORIZED, 3); $this->response(UNAUTHORIZED, 3);
} }
} }

View File

@@ -19,6 +19,9 @@ class SuperUserController extends BaseController
*/ */
public function auth() public function auth()
{ {
// Debug point
echo json_encode(["status" => "reached auth"]); die;
$inputUsername = $this->post('username'); $inputUsername = $this->post('username');
$inputPassword = $this->post('password'); $inputPassword = $this->post('password');