Spaces:
Running
Running
Update tamplates/verify.html
Browse files- templates/verify.html +99 -4
templates/verify.html
CHANGED
|
@@ -85,7 +85,7 @@
|
|
| 85 |
<div class="verify-card">
|
| 86 |
<div class="verify-icon"><i class="fas fa-envelope"></i></div>
|
| 87 |
<h2>Verifikasi Akun</h2>
|
| 88 |
-
<p>
|
| 89 |
<div class="destination" id="destination">Memuat...</div>
|
| 90 |
|
| 91 |
<div class="code-input" id="codeInputs">
|
|
@@ -98,7 +98,7 @@
|
|
| 98 |
</div>
|
| 99 |
<input type="hidden" id="userId" value="{{ user_id }}">
|
| 100 |
|
| 101 |
-
<button class="btn-verify" onclick="verifyCode()">
|
| 102 |
<i class="fas fa-check"></i> Verifikasi
|
| 103 |
</button>
|
| 104 |
|
|
@@ -113,16 +113,39 @@
|
|
| 113 |
</div>
|
| 114 |
|
| 115 |
<script>
|
|
|
|
| 116 |
let countdownInterval = null;
|
| 117 |
let resendCount = 0;
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
const destination = sessionStorage.getItem('verify_destination');
|
| 120 |
-
if (destination)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
const digits = document.querySelectorAll('.code-digit');
|
| 123 |
digits.forEach((digit, index) => {
|
| 124 |
digit.addEventListener('input', (e) => {
|
| 125 |
-
if (e.target.value.length === 1 && index < 5)
|
|
|
|
|
|
|
| 126 |
});
|
| 127 |
digit.addEventListener('keydown', (e) => {
|
| 128 |
if (e.key === 'Backspace' && !e.target.value && index > 0) {
|
|
@@ -130,6 +153,14 @@
|
|
| 130 |
digits[index - 1].value = '';
|
| 131 |
}
|
| 132 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
});
|
| 134 |
|
| 135 |
function startCountdown(seconds = 60) {
|
|
@@ -152,6 +183,70 @@
|
|
| 152 |
}
|
| 153 |
startCountdown(60);
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
setTimeout(() => { if (digits[0]) digits[0].focus(); }, 100);
|
| 156 |
</script>
|
| 157 |
<script src="{{ url_for('static', filename='js/auth.js') }}"></script>
|
|
|
|
| 85 |
<div class="verify-card">
|
| 86 |
<div class="verify-icon"><i class="fas fa-envelope"></i></div>
|
| 87 |
<h2>Verifikasi Akun</h2>
|
| 88 |
+
<p>Masukkan kode verifikasi 6 digit</p>
|
| 89 |
<div class="destination" id="destination">Memuat...</div>
|
| 90 |
|
| 91 |
<div class="code-input" id="codeInputs">
|
|
|
|
| 98 |
</div>
|
| 99 |
<input type="hidden" id="userId" value="{{ user_id }}">
|
| 100 |
|
| 101 |
+
<button class="btn-verify" id="verifyBtn" onclick="verifyCode()">
|
| 102 |
<i class="fas fa-check"></i> Verifikasi
|
| 103 |
</button>
|
| 104 |
|
|
|
|
| 113 |
</div>
|
| 114 |
|
| 115 |
<script>
|
| 116 |
+
let userId = null;
|
| 117 |
let countdownInterval = null;
|
| 118 |
let resendCount = 0;
|
| 119 |
|
| 120 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 121 |
+
userId = urlParams.get('user_id');
|
| 122 |
+
|
| 123 |
+
if (!userId) {
|
| 124 |
+
userId = sessionStorage.getItem('pending_user_id');
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
const destination = sessionStorage.getItem('verify_destination');
|
| 128 |
+
if (destination) {
|
| 129 |
+
document.getElementById('destination').innerHTML = destination;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
const codeFromUrl = urlParams.get('code');
|
| 133 |
+
if (codeFromUrl && codeFromUrl.length === 6) {
|
| 134 |
+
const digits = document.querySelectorAll('.code-digit');
|
| 135 |
+
for (let i = 0; i < codeFromUrl.length; i++) {
|
| 136 |
+
if (digits[i]) digits[i].value = codeFromUrl[i];
|
| 137 |
+
}
|
| 138 |
+
setTimeout(() => {
|
| 139 |
+
verifyCode();
|
| 140 |
+
}, 500);
|
| 141 |
+
}
|
| 142 |
|
| 143 |
const digits = document.querySelectorAll('.code-digit');
|
| 144 |
digits.forEach((digit, index) => {
|
| 145 |
digit.addEventListener('input', (e) => {
|
| 146 |
+
if (e.target.value.length === 1 && index < 5) {
|
| 147 |
+
digits[index + 1].focus();
|
| 148 |
+
}
|
| 149 |
});
|
| 150 |
digit.addEventListener('keydown', (e) => {
|
| 151 |
if (e.key === 'Backspace' && !e.target.value && index > 0) {
|
|
|
|
| 153 |
digits[index - 1].value = '';
|
| 154 |
}
|
| 155 |
});
|
| 156 |
+
digit.addEventListener('paste', (e) => {
|
| 157 |
+
e.preventDefault();
|
| 158 |
+
const pastedData = e.clipboardData.getData('text');
|
| 159 |
+
if (pastedData.length === 6 && /^\d+$/.test(pastedData)) {
|
| 160 |
+
digits.forEach((d, i) => { d.value = pastedData[i]; });
|
| 161 |
+
verifyCode();
|
| 162 |
+
}
|
| 163 |
+
});
|
| 164 |
});
|
| 165 |
|
| 166 |
function startCountdown(seconds = 60) {
|
|
|
|
| 183 |
}
|
| 184 |
startCountdown(60);
|
| 185 |
|
| 186 |
+
async function verifyCode() {
|
| 187 |
+
let code = '';
|
| 188 |
+
digits.forEach(digit => { code += digit.value; });
|
| 189 |
+
|
| 190 |
+
if (code.length !== 6) {
|
| 191 |
+
showToast('Masukkan kode 6 digit', 'error');
|
| 192 |
+
return;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
const verifyBtn = document.getElementById('verifyBtn');
|
| 196 |
+
verifyBtn.disabled = true;
|
| 197 |
+
verifyBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Memverifikasi...';
|
| 198 |
+
|
| 199 |
+
const result = await apiCall('/api/auth/verify', {
|
| 200 |
+
method: 'POST',
|
| 201 |
+
body: JSON.stringify({ user_id: userId, code: code })
|
| 202 |
+
});
|
| 203 |
+
|
| 204 |
+
if (result && result.success) {
|
| 205 |
+
showToast('✅ Akun berhasil diverifikasi!', 'success');
|
| 206 |
+
sessionStorage.removeItem('pending_user_id');
|
| 207 |
+
sessionStorage.removeItem('verify_destination');
|
| 208 |
+
sessionStorage.removeItem('verification_code');
|
| 209 |
+
setTimeout(() => {
|
| 210 |
+
window.location.href = '/login?verified=true';
|
| 211 |
+
}, 1500);
|
| 212 |
+
} else if (result && result.error) {
|
| 213 |
+
showToast(result.error, 'error');
|
| 214 |
+
verifyBtn.disabled = false;
|
| 215 |
+
verifyBtn.innerHTML = '<i class="fas fa-check"></i> Verifikasi';
|
| 216 |
+
} else {
|
| 217 |
+
verifyBtn.disabled = false;
|
| 218 |
+
verifyBtn.innerHTML = '<i class="fas fa-check"></i> Verifikasi';
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
async function resendCode(event) {
|
| 223 |
+
event.preventDefault();
|
| 224 |
+
|
| 225 |
+
if (resendCount >= 3) {
|
| 226 |
+
showToast('Anda telah mencoba 3 kali. Hubungi admin.', 'error');
|
| 227 |
+
return;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
const resendBtn = document.getElementById('resendBtn');
|
| 231 |
+
resendBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Mengirim...';
|
| 232 |
+
|
| 233 |
+
const result = await apiCall('/api/auth/resend-code', {
|
| 234 |
+
method: 'POST',
|
| 235 |
+
body: JSON.stringify({ user_id: userId })
|
| 236 |
+
});
|
| 237 |
+
|
| 238 |
+
if (result && result.success) {
|
| 239 |
+
showToast('Kode baru: ' + result.verification_code, 'success');
|
| 240 |
+
sessionStorage.setItem('verification_code', result.verification_code);
|
| 241 |
+
resendCount++;
|
| 242 |
+
startCountdown(60);
|
| 243 |
+
} else if (result && result.error) {
|
| 244 |
+
showToast(result.error, 'error');
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
resendBtn.innerHTML = '<i class="fas fa-redo-alt"></i> Kirim ulang kode';
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
setTimeout(() => { if (digits[0]) digits[0].focus(); }, 100);
|
| 251 |
</script>
|
| 252 |
<script src="{{ url_for('static', filename='js/auth.js') }}"></script>
|