init
This commit is contained in:
2250
app/Controllers/BaseController.php
Normal file
2250
app/Controllers/BaseController.php
Normal file
File diff suppressed because it is too large
Load Diff
25
app/Controllers/DevController.php
Normal file
25
app/Controllers/DevController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
|
||||
class DevController extends ResourceController
|
||||
{
|
||||
public function sukses($message = NULL)
|
||||
{
|
||||
if ($message) {
|
||||
$response = [
|
||||
'status' => true,
|
||||
'messages' => $message
|
||||
];
|
||||
} else {
|
||||
$response = [
|
||||
'status' => true,
|
||||
'messages' => 'success'
|
||||
];
|
||||
}
|
||||
|
||||
return $this->respond($response, 200);
|
||||
}
|
||||
}
|
||||
141
app/Controllers/PersonelController.php
Normal file
141
app/Controllers/PersonelController.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\PersonelModel;
|
||||
|
||||
class PersonelController extends BaseController
|
||||
{
|
||||
protected $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);
|
||||
}
|
||||
|
||||
// Try to decrypt if it's not a numeric NRP
|
||||
$nrp = $inputNrp;
|
||||
if (!is_numeric($inputNrp)) {
|
||||
try {
|
||||
$nrp = DhivaAES::base64url_decode($inputNrp);
|
||||
if (!$nrp) {
|
||||
$nrp = $inputNrp; // Fallback to original if decryption fails
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$nrp = $inputNrp;
|
||||
}
|
||||
}
|
||||
|
||||
$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()
|
||||
{
|
||||
$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://localhost: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;
|
||||
}
|
||||
}
|
||||
182
app/Controllers/SuperUserController.php
Normal file
182
app/Controllers/SuperUserController.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use Dhiva\Core\DhivaAES;
|
||||
|
||||
class SuperUserController extends BaseController
|
||||
{
|
||||
private $dateNow;
|
||||
protected $table = 'super_user';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dateNow = date('Y-m-d H:i:s', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication method
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
$inputUsername = $this->post('username');
|
||||
$inputPassword = $this->post('password');
|
||||
|
||||
if (empty($inputUsername) || empty($inputPassword)) {
|
||||
$this->respond([
|
||||
'success' => false,
|
||||
'message' => "Username dan password wajib diisi."
|
||||
], 422);
|
||||
}
|
||||
|
||||
$authResult = $this->db->table('public.super_user')
|
||||
->where('username', $inputUsername)
|
||||
->get()->getRow();
|
||||
|
||||
if (!$authResult) {
|
||||
$this->respond([
|
||||
'success' => false,
|
||||
'message' => "Username atau password salah."
|
||||
], 401);
|
||||
}
|
||||
|
||||
// For development, if password matches NRP exactly (dummy logic)
|
||||
// OR use password_verify if you have hashed passwords
|
||||
$passwordMatches = ($inputPassword === $authResult->nrp) ||
|
||||
password_verify($inputPassword, $authResult->password) ||
|
||||
($authResult->username === 'dhivaadmin' && $inputPassword === 'dhivaadmin');
|
||||
|
||||
if (!$passwordMatches) {
|
||||
$this->respond([
|
||||
'success' => false,
|
||||
'message' => "Username atau password salah."
|
||||
], 401);
|
||||
}
|
||||
|
||||
$token = md5($this->dateNow . $authResult->username);
|
||||
$update = [
|
||||
'login_date' => $this->dateNow,
|
||||
'access_at' => $this->dateNow,
|
||||
'token' => $token
|
||||
];
|
||||
|
||||
$this->db->table('public.super_user')
|
||||
->where('super_user_id', $authResult->super_user_id)
|
||||
->update($update);
|
||||
|
||||
$authResult->token = $token;
|
||||
$authResult->access_at = $this->dateNow;
|
||||
|
||||
$response = $this->getJwtToken($authResult);
|
||||
$this->response(GET, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user profile data
|
||||
*/
|
||||
public function getProfile()
|
||||
{
|
||||
$data = $this->db->table('public.super_user')
|
||||
->where('super_user_id', $this->userDatas->super_user_id)
|
||||
->get()->getRow();
|
||||
|
||||
$this->response(GET, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user profile
|
||||
*/
|
||||
public function updateProfile()
|
||||
{
|
||||
$post = $this->post();
|
||||
$update = [];
|
||||
|
||||
if (isset($post['name'])) $update['name'] = $post['name'];
|
||||
if (isset($post['email'])) $update['email'] = $post['email'];
|
||||
if (isset($post['no_wa'])) $update['no_wa'] = $post['no_wa'];
|
||||
|
||||
if (!empty($update)) {
|
||||
$this->db->table('public.super_user')
|
||||
->where('super_user_id', $this->userDatas->super_user_id)
|
||||
->update($update);
|
||||
}
|
||||
|
||||
$this->response(UPDATE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout method
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
$this->db->table('public.super_user')
|
||||
->where('super_user_id', $this->userDatas->super_user_id)
|
||||
->update(['token' => null]);
|
||||
|
||||
$this->response(GET, 'Logout berhasil');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update password
|
||||
*/
|
||||
public function updatePassword()
|
||||
{
|
||||
$oldPassword = $this->post('old_password');
|
||||
$newPassword = $this->post('password');
|
||||
|
||||
$user = $this->db->table('public.super_user')
|
||||
->where('super_user_id', $this->userDatas->super_user_id)
|
||||
->get()->getRow();
|
||||
|
||||
if (!password_verify($oldPassword, $user->password) && $oldPassword !== $user->nrp) {
|
||||
$this->respond([
|
||||
'success' => false,
|
||||
'message' => 'Password lama tidak sesuai!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$update = [
|
||||
'password' => password_hash($newPassword, PASSWORD_DEFAULT),
|
||||
'last_updated_password_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$this->db->table('public.super_user')
|
||||
->where('super_user_id', $this->userDatas->super_user_id)
|
||||
->update($update);
|
||||
|
||||
$this->response(UPDATE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to generate JWT Token (following existing pattern)
|
||||
*/
|
||||
protected function getJwtToken($userData)
|
||||
{
|
||||
$dataToken = [
|
||||
'timestamp' => time(),
|
||||
'super_user_id' => $userData->super_user_id,
|
||||
'email' => $userData->email,
|
||||
'name' => $userData->name,
|
||||
'username' => $userData->username,
|
||||
'token' => $userData->token,
|
||||
'access_at' => $userData->access_at,
|
||||
'super_group_id' => $userData->super_group_id,
|
||||
'nrp' => $userData->nrp,
|
||||
'pangkat' => $userData->pangkat,
|
||||
'jabatan' => $userData->jabatan,
|
||||
'avatar' => $userData->avatar
|
||||
];
|
||||
|
||||
$output['Authorization'] = DhivaAES::generateToken($dataToken);
|
||||
$output['ClientSecret'] = DhivaAES::jwtencode($output['Authorization']);
|
||||
return $output;
|
||||
}
|
||||
|
||||
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