personelModel = new PersonelModel(); } /** * Get basic profile info by NRP (supports encrypted NRP) */ public function getProfil() { $inputNrp = $this->request->getGet('nrp'); if (!$inputNrp) { return $this->response(UNAUTHORIZED, 1); } // Try to decrypt if it's not a numeric NRP $nrp = $inputNrp; if (!is_numeric($inputNrp)) { try { $decrypted = DhivaAES::base64url_decode($inputNrp); if ($decrypted !== false && !empty($decrypted)) { $nrp = $decrypted; } } catch (\Exception $e) { // Keep original if crash } } $personel = $this->personelModel->where('nrp', $nrp)->first(); if (!$personel) { $response = [ 'status' => 'error', 'message' => 'Personel tidak ditemukan', 'data' => null ]; return $this->respond($response, 404); } $response = [ 'status' => 'success', 'message' => 'Data personel ditemukan', 'data' => $personel ]; $this->respond($response); } /** * Get full DRH by NRP and OTP (supports encrypted NRP) */ public function getDaftarRiwayatHidup() { $inputNrp = $this->request->getGet('nrp'); $otp = $this->request->getGet('otp'); // Try to decrypt if it's not a numeric NRP $nrp = $inputNrp; if (!is_numeric($inputNrp)) { $nrp = DhivaAES::base64url_decode($inputNrp) ?: $inputNrp; } if ($otp !== '4444') { $this->respond([ 'status' => 'error', 'message' => 'OTP tidak valid', 'data' => null ], 401); } if (!$nrp) { $this->respond([ 'status' => 'error', 'message' => 'NRP wajib diisi', 'data' => null ], 400); } $drh = $this->personelModel->getFullDRH($nrp); if (!$drh) { $this->respond([ 'status' => 'error', 'message' => 'Data riwayat hidup tidak ditemukan', 'data' => null ], 404); } $response = [ 'status' => 'success', 'message' => 'Data riwayat hidup berhasil diambil', 'data' => $drh ]; $this->respond($response); } /** * Generate Encrypted URL for Barcode (Admin only) */ public function generateEncryptedLink() { $json = $this->request->getJSON(); $nrp = $json ? $json->nrp : $this->request->getPost('nrp'); if (!$nrp) { $this->respond(['status' => 'error', 'message' => 'NRP wajib diisi'], 400); } $encryptedNrp = DhivaAES::base64url_encode($nrp); $response = [ 'status' => 'success', 'data' => [ 'nrp' => $nrp, 'encrypted_nrp' => $encryptedNrp, 'url' => "http://192.168.1.11:4200/kta/profil/" . $encryptedNrp ] ]; $this->respond($response); } private function respond($data, $code = 200) { header('Content-Type: application/json'); http_response_code($code); echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); die; } }