This commit is contained in:
2026-01-30 17:20:52 +09:00
commit 21b6332c9c
459 changed files with 190743 additions and 0 deletions

102
kngil/js/login_sms.js Normal file
View File

@@ -0,0 +1,102 @@
document.addEventListener('DOMContentLoaded', () => {
const smsBtn = document.getElementById('sms_button');
const phoneInp = document.getElementById('login_phone');
if (!smsBtn || !phoneInp) return;
const form = smsBtn.closest('form');
const infoBox = form.querySelector('.info-box');
const timerEl = form.querySelector('.timer');
let pollTimer = null;
let timerIntv = null;
let remain = 180; // 3분
function startTimer() {
clearInterval(timerIntv);
remain = 180;
timerEl.classList.remove('d-none');
updateTimer();
timerIntv = setInterval(() => {
remain--;
updateTimer();
if (remain <= 0) {
clearInterval(timerIntv);
smsBtn.disabled = false;
timerEl.textContent = '00:00';
}
}, 1000);
}
function updateTimer() {
const m = String(Math.floor(remain / 60)).padStart(2, '0');
const s = String(remain % 60).padStart(2, '0');
timerEl.textContent = `${m}:${s}`;
}
smsBtn.addEventListener('click', async (e) => {
e.preventDefault();
const phone = phoneInp.value.trim();
if (!phone) {
alert('휴대폰 번호를 입력하세요.');
phoneInp.focus();
return;
}
smsBtn.disabled = true;
try {
const res = await fetch('/kngil/bbs/login_sms.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
mode: 'request',
phone
})
});
const json = await res.json();
if (json.status !== 'success') {
alert(json.message || '인증 링크 요청 실패');
smsBtn.disabled = false;
return;
}
// UI 처리
infoBox.classList.remove('d-none');
startTimer();
startPolling();
} catch (err) {
console.error(err);
alert('인증 요청 중 오류');
smsBtn.disabled = false;
}
});
function startPolling() {
clearInterval(pollTimer);
pollTimer = setInterval(async () => {
try {
const res = await fetch('/kngil/bbs/login_sms.php?mode=status');
const json = await res.json();
if (json.status === 'success') {
clearInterval(pollTimer);
clearInterval(timerIntv);
location.reload();
}
} catch (e) {
console.error(e);
}
}, 3000);
}
});