This commit is contained in:
Naden
2026-04-25 17:11:06 +07:00
parent 47e9949cef
commit 27cc2cf763

View File

@@ -7,137 +7,137 @@ use Dhiva\Core\DhivaAES;
class PersonelController extends BaseController
{
protected $personelModel;
protected $personelModel;
public function __construct()
{
$this->personelModel = new PersonelModel();
public function __construct()
{
$this->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);
}
/**
* 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;
}
// 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);
} catch (\Exception $e) {
// Keep original if crash
}
}
/**
* 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;
}
$personel = $this->personelModel->where('nrp', $nrp)->first();
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);
if (!$personel) {
$response = [
'status' => 'error',
'message' => 'Personel tidak ditemukan',
'data' => null
];
return $this->respond($response, 404);
}
/**
* 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);
}
$response = [
'status' => 'success',
'message' => 'Data personel ditemukan',
'data' => $personel
];
$encryptedNrp = DhivaAES::base64url_encode($nrp);
$response = [
'status' => 'success',
'data' => [
'nrp' => $nrp,
'encrypted_nrp' => $encryptedNrp,
'url' => "http://localhost:4200/kta/profil/" . $encryptedNrp
]
];
$this->respond($response);
}
$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;
}
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;
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;
}
}