Merge pull request 'Pembaruan Link generate WA' (#41) from development into main
Reviewed-on: #41
This commit was merged in pull request #41.
This commit is contained in:
@@ -3,7 +3,10 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Models\Verifikator\VerifikasiAbsenToken;
|
use App\Models\Verifikator\VerifikasiAbsenToken;
|
||||||
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class VerifikasiAbsenLinkService
|
class VerifikasiAbsenLinkService
|
||||||
@@ -118,7 +121,23 @@ class VerifikasiAbsenLinkService
|
|||||||
return null;
|
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
|
public function markUsed(int $pengajuanId, string $token): void
|
||||||
|
|||||||
Reference in New Issue
Block a user