Remove client side attempts and lockedUntil logic to avoid local state desync with server database
This commit is contained in:
@@ -687,23 +687,15 @@ function openAuthModal(mode){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client-side rate limiting check
|
// Client-side cooldown check
|
||||||
const limitKey = 'webgis_limit_' + btoa(email);
|
const limitKey = 'webgis_limit_' + btoa(email);
|
||||||
let limitInfo = { attempts: 0, lastTime: 0, lockedUntil: 0 };
|
let limitInfo = { lastTime: 0 };
|
||||||
try{
|
try{
|
||||||
const cached = localStorage.getItem(limitKey);
|
const cached = localStorage.getItem(limitKey);
|
||||||
if(cached) limitInfo = JSON.parse(cached);
|
if(cached) limitInfo = JSON.parse(cached);
|
||||||
}catch(e){}
|
}catch(e){}
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if(limitInfo.lockedUntil && now < limitInfo.lockedUntil){
|
|
||||||
const diff = limitInfo.lockedUntil - now;
|
|
||||||
const hours = Math.floor(diff / (3600 * 1000));
|
|
||||||
const mins = Math.ceil((diff % (3600 * 1000)) / (60 * 1000));
|
|
||||||
showToast(`Batas pengiriman kode tercapai. Anda harus menunggu ${hours} jam ${mins} menit lagi.`, 'error', 5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(limitInfo.lastTime && now - limitInfo.lastTime < 30 * 1000){
|
if(limitInfo.lastTime && now - limitInfo.lastTime < 30 * 1000){
|
||||||
const remaining = Math.ceil((30 * 1000 - (now - limitInfo.lastTime)) / 1000);
|
const remaining = Math.ceil((30 * 1000 - (now - limitInfo.lastTime)) / 1000);
|
||||||
showToast(`Silakan tunggu ${remaining} detik sebelum mengirim kembali.`, 'error', 3000);
|
showToast(`Silakan tunggu ${remaining} detik sebelum mengirim kembali.`, 'error', 3000);
|
||||||
@@ -725,26 +717,13 @@ function openAuthModal(mode){
|
|||||||
if(!resp.ok || (jr && jr.success === false)){
|
if(!resp.ok || (jr && jr.success === false)){
|
||||||
const errMessage = jr && jr.message ? jr.message : (jr && jr.error ? jr.error : 'Gagal mengirim kode');
|
const errMessage = jr && jr.message ? jr.message : (jr && jr.error ? jr.error : 'Gagal mengirim kode');
|
||||||
showToast(errMessage, 'error', 5000);
|
showToast(errMessage, 'error', 5000);
|
||||||
|
|
||||||
// If locked on server side, sync client side state
|
|
||||||
if(jr && jr.error === 'locked_24h' && jr.locked_until){
|
|
||||||
limitInfo.lockedUntil = jr.locked_until;
|
|
||||||
try{ localStorage.setItem(limitKey, JSON.stringify(limitInfo)); }catch(e){}
|
|
||||||
}
|
|
||||||
|
|
||||||
sendCodeBtn.disabled = false;
|
sendCodeBtn.disabled = false;
|
||||||
sendCodeBtn.textContent = 'Kirim Kode Verifikasi';
|
sendCodeBtn.textContent = 'Kirim Kode Verifikasi';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update client side rate limiting on success
|
// Update client side cooldown info on success
|
||||||
limitInfo.attempts = (limitInfo.lockedUntil && now >= limitInfo.lockedUntil) ? 1 : (limitInfo.attempts + 1);
|
|
||||||
limitInfo.lastTime = now;
|
limitInfo.lastTime = now;
|
||||||
if(limitInfo.attempts >= 3){
|
|
||||||
limitInfo.lockedUntil = now + 24 * 3600 * 1000;
|
|
||||||
} else {
|
|
||||||
limitInfo.lockedUntil = 0;
|
|
||||||
}
|
|
||||||
try{ localStorage.setItem(limitKey, JSON.stringify(limitInfo)); }catch(e){}
|
try{ localStorage.setItem(limitKey, JSON.stringify(limitInfo)); }catch(e){}
|
||||||
|
|
||||||
authRegisterState.code_sent = true;
|
authRegisterState.code_sent = true;
|
||||||
@@ -756,9 +735,9 @@ function openAuthModal(mode){
|
|||||||
codeInput.value = jr.debug_code;
|
codeInput.value = jr.debug_code;
|
||||||
showToast('Gagal mengirim email. Menggunakan kode pengujian: ' + jr.debug_code, 'warning', 8000);
|
showToast('Gagal mengirim email. Menggunakan kode pengujian: ' + jr.debug_code, 'warning', 8000);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
showToast('Kode verifikasi terkirim ke email Anda! Silakan cek email Anda.', 'success', 6000);
|
showToast('Kode verifikasi terkirim ke email Anda! Silakan cek email Anda.', 'success', 6000);
|
||||||
|
}
|
||||||
|
|
||||||
// Cooldown countdown timer
|
// Cooldown countdown timer
|
||||||
let cooldown = 30;
|
let cooldown = 30;
|
||||||
|
|||||||
Reference in New Issue
Block a user