update
This commit is contained in:
@@ -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');
|
||||
$personel = $this->personelModel->where('nrp', $nrp)->first();
|
||||
|
||||
// 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);
|
||||
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');
|
||||
$response = [
|
||||
'status' => 'success',
|
||||
'message' => 'Data personel ditemukan',
|
||||
'data' => $personel
|
||||
];
|
||||
|
||||
if (!$nrp) {
|
||||
$this->respond(['status' => 'error', 'message' => 'NRP wajib diisi'], 400);
|
||||
}
|
||||
$this->respond($response);
|
||||
}
|
||||
|
||||
$encryptedNrp = DhivaAES::base64url_encode($nrp);
|
||||
/**
|
||||
* Get full DRH by NRP and OTP (supports encrypted NRP)
|
||||
*/
|
||||
public function getDaftarRiwayatHidup()
|
||||
{
|
||||
$inputNrp = $this->request->getGet('nrp');
|
||||
$otp = $this->request->getGet('otp');
|
||||
|
||||
$response = [
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'nrp' => $nrp,
|
||||
'encrypted_nrp' => $encryptedNrp,
|
||||
'url' => "http://localhost:4200/kta/profil/" . $encryptedNrp
|
||||
]
|
||||
];
|
||||
|
||||
$this->respond($response);
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user