Compare commits

..

2 Commits

Author SHA1 Message Date
arbi c10cdf39ca Merge pull request 'Revert "Perbaikan API WA" dan "Perbaikan Generate Token Baru"' (#27) from development into main
Reviewed-on: #27
2026-09-27 16:34:04 +07:00
Ariyutta 6672f34adc Revert "Perbaikan API WA" dan "Perbaikan Generate Token Baru"
Mengembalikan fitur verifikasi presensi via WhatsApp ke kondisi semula
sebelum perubahan mekanisme regenerasi token sesi.

This reverts commit 1d58c66a7a.
This reverts commit dcf57bcfdc.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 16:32:21 +07:00
4 changed files with 21 additions and 118 deletions
@@ -36,7 +36,7 @@ class VerifikasiAbsenController extends Controller
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
if (! $otorisasi['ok']) {
if (is_array($otorisasi)) {
return $this->responseTidakBerwenang($otorisasi['reason']);
}
@@ -47,37 +47,6 @@ class VerifikasiAbsenController extends Controller
]);
}
/**
* Terbitkan token baru untuk tautan yang sesinya sudah habis (dipicu tombol "Minta Token Baru").
*/
public function perbaruiToken(Request $request, int $id): JsonResponse
{
$pengajuan = PengajuanPresensi::findOrFail($id);
if ($pengajuan->status !== 'Diajukan') {
return response()->json([
'success' => false,
'state' => 'already_processed',
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
], 422);
}
$tokenBaru = $this->linkService->regenerate($id, $request->input('token'));
if (! $tokenBaru) {
return response()->json([
'success' => false,
'state' => 'link_expired',
'message' => 'Tautan verifikasi ini sudah tidak valid. Silakan minta tautan verifikasi baru.',
], 403);
}
return response()->json([
'success' => true,
'new_token' => $tokenBaru,
]);
}
public function setujui(Request $request, int $id): JsonResponse
{
$request->validate([
@@ -89,11 +58,11 @@ class VerifikasiAbsenController extends Controller
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
if (! $otorisasi['ok']) {
if (is_array($otorisasi)) {
return $this->responseTidakBerwenang($otorisasi['reason']);
}
$nipAtasan = $otorisasi['nip'];
$nipAtasan = $otorisasi;
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
return $gagal;
@@ -148,11 +117,11 @@ class VerifikasiAbsenController extends Controller
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
if (! $otorisasi['ok']) {
if (is_array($otorisasi)) {
return $this->responseTidakBerwenang($otorisasi['reason']);
}
$nipAtasan = $otorisasi['nip'];
$nipAtasan = $otorisasi;
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
return $gagal;
@@ -232,23 +201,23 @@ class VerifikasiAbsenController extends Controller
}
/**
* @return array{ok: bool, nip: ?string, reason: ?string, new_token: ?string}
* @return string|array{reason: string} Nip atasan kalau berhasil, atau array alasan gagal.
*/
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan, bool $renewSesi = false): array
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|array
{
$token = $request->input('token');
$hasil = $this->linkService->verify($pengajuan->id, $token, $renewSesi);
$hasil = $this->linkService->verify($pengajuan->id, $token);
if (! $hasil['ok']) {
return ['ok' => false, 'nip' => null, 'reason' => $hasil['reason'], 'new_token' => null];
return ['reason' => $hasil['reason']];
}
if (! $this->dawaiService->isAtasanDari($hasil['nip'], $pengajuan->nip)) {
return ['ok' => false, 'nip' => null, 'reason' => 'invalid', 'new_token' => null];
return ['reason' => 'invalid'];
}
return ['ok' => true, 'nip' => $hasil['nip'], 'reason' => null, 'new_token' => $hasil['new_token']];
return $hasil['nip'];
}
private function responseTidakBerwenang(string $reason): JsonResponse
@@ -76,36 +76,6 @@ class VerifikasiAbsenLinkService
return ['ok' => true, 'nip' => $row->nip, 'reason' => null];
}
/**
* Terbitkan token baru untuk pengajuan yang sesinya sudah habis, dipicu lewat aksi eksplisit
* (tombol "Minta Token Baru" di halaman error), bukan otomatis saat tautan dibuka ulang.
* Token lama tetap harus dikenali (belum invalid) dan link belum lewat masa berlaku (5 hari).
*/
public function regenerate(int $pengajuanId, ?string $token): ?string
{
if (! $token) {
return null;
}
$row = VerifikasiAbsenToken::where('pengajuan_id', $pengajuanId)
->where('token', $this->hash($token))
->where('purpose', self::PURPOSE)
->first();
if (! $row || now()->greaterThan($row->expires_at)) {
return null;
}
$tokenBaru = Str::random(40);
$row->update([
'token' => $this->hash($tokenBaru),
'first_accessed_at' => null,
]);
return $tokenBaru;
}
public function markUsed(int $pengajuanId, string $token): void
{
VerifikasiAbsenToken::where('pengajuan_id', $pengajuanId)
@@ -124,9 +124,6 @@
<div class="text-center py-4">
<i id="pesanIcon" class="fas fa-info-circle fa-3x text-secondary mb-3"></i>
<p id="pesanText" class="mb-0"></p>
<button type="button" class="btn btn-primary mt-3 d-none" id="btnMintaTokenBaru">
<i class="fas fa-rotate-right"></i> Minta Token Baru
</button>
</div>
</div>
@@ -213,7 +210,7 @@
<script>
const pengajuanId = {{ (int) $id }};
let token = new URLSearchParams(window.location.search).get('token');
const token = new URLSearchParams(window.location.search).get('token');
const apiBase = "{{ url('/api/v1/verifikasi-absen') }}/" + pengajuanId;
function showNotification(status, title, text) {
@@ -232,16 +229,13 @@
});
}
function ambilDataError(xhr) {
try {
return JSON.parse(xhr.responseText);
} catch (e) {
return {};
}
}
function ambilPesanError(xhr) {
return ambilDataError(xhr).message || 'Terjadi kesalahan. Silakan coba lagi.';
try {
const data = JSON.parse(xhr.responseText);
return data.message || 'Terjadi kesalahan. Silakan coba lagi.';
} catch (e) {
return 'Terjadi kesalahan. Silakan coba lagi.';
}
}
const statusBadgeMap = {
@@ -250,12 +244,11 @@
'Ditolak': ['bg-danger', 'Ditolak'],
};
function tampilkanPesan(icon, text, colorClass, bisaMintaTokenBaru = false) {
function tampilkanPesan(icon, text, colorClass) {
$('#pesanState').removeClass('d-none');
$('#detailState').addClass('d-none');
$('#pesanIcon').attr('class', `fas ${icon} fa-3x mb-3 ${colorClass}`);
$('#pesanText').text(text);
$('#btnMintaTokenBaru').toggleClass('d-none', !bisaMintaTokenBaru);
}
function tampilkanDetail(data, state) {
@@ -299,41 +292,13 @@
selesaiLoading();
},
error: function (xhr) {
const data = ambilDataError(xhr);
tampilkanPesan('fa-exclamation-triangle', data.message || 'Terjadi kesalahan. Silakan coba lagi.', 'text-danger', data.state === 'session_expired');
const pesan = ambilPesanError(xhr);
tampilkanPesan('fa-exclamation-triangle', pesan, 'text-danger');
selesaiLoading();
}
});
}
$('#btnMintaTokenBaru').on('click', function () {
const $btn = $(this);
const originalText = $btn.html();
$btn.prop('disabled', true).text('Memproses...');
$.ajax({
url: `${apiBase}/perbarui-token?token=${encodeURIComponent(token)}`,
method: 'POST',
data: { token },
success: function (res) {
token = res.new_token;
const url = new URL(window.location.href);
url.searchParams.set('token', token);
window.history.replaceState({}, '', url);
$('#loadingState').removeClass('d-none');
$('#mainCard').addClass('d-none');
muatData();
},
error: function (xhr) {
showNotification('error', 'Gagal', ambilPesanError(xhr));
},
complete: function () {
$btn.prop('disabled', false).html(originalText);
}
});
});
function selesaiLoading() {
$('#loadingState').addClass('d-none');
$('#mainCard').removeClass('d-none');
-1
View File
@@ -116,7 +116,6 @@ Route::prefix('v1')->group(function () {
Route::prefix('/verifikasi-absen')->name('verifikasi-absen.')->group(function () {
Route::post('/link', [VerifikasiAbsenLinkController::class, 'generate'])->name('link');
Route::get('/{id}', [VerifikasiAbsenController::class, 'show'])->name('show');
Route::post('/{id}/perbarui-token', [VerifikasiAbsenController::class, 'perbaruiToken'])->name('perbarui-token');
Route::post('/{id}/setujui', [VerifikasiAbsenController::class, 'setujui'])->name('setujui');
Route::post('/{id}/tolak', [VerifikasiAbsenController::class, 'tolak'])->name('tolak');
});