From ad6246d9514ae7bdc26e283a6c7031873bf32864 Mon Sep 17 00:00:00 2001 From: Ariyutta Date: Wed, 30 Sep 2026 11:59:01 +0700 Subject: [PATCH] Pembaruan Link generate WA --- app/Services/VerifikasiAbsenLinkService.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Services/VerifikasiAbsenLinkService.php b/app/Services/VerifikasiAbsenLinkService.php index 10d5c22c..cced152c 100644 --- a/app/Services/VerifikasiAbsenLinkService.php +++ b/app/Services/VerifikasiAbsenLinkService.php @@ -3,7 +3,10 @@ namespace App\Services; use App\Models\Verifikator\VerifikasiAbsenToken; +use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Str; class VerifikasiAbsenLinkService @@ -118,7 +121,23 @@ class VerifikasiAbsenLinkService return null; } - return $this->buatToken($pengajuanId, $row->nip, $row->expires_at); + // Token pengganti yang sesinya masih jalan dipakai ulang, jangan buat baru tiap tombol WA diklik. + // Token di DB hanya berupa hash, jadi plaintext pengganti disimpan (terenkripsi) di cache selama sesinya. + $kunciCache = "verifikasi-absen:pengganti:{$row->id}"; + + if ($tersimpan = Cache::get($kunciCache)) { + try { + return Crypt::decryptString($tersimpan); + } catch (DecryptException) { + Cache::forget($kunciCache); + } + } + + $tokenBaru = $this->buatToken($pengajuanId, $row->nip, $row->expires_at); + + Cache::put($kunciCache, Crypt::encryptString($tokenBaru), now()->addMinutes(self::SESI_MENIT)); + + return $tokenBaru; } public function markUsed(int $pengajuanId, string $token): void