Files
kngil_home/kngil/js/login.js

64 lines
2.0 KiB
JavaScript

const form = document.querySelector('.tab-content.id form')
if (form) {
form.addEventListener('submit', async (e) => {
e.preventDefault()
const id = document.getElementById('login_id').value.trim()
const pw = document.getElementById('login_password').value.trim()
if (!id || !pw) {
alert('아이디와 비밀번호를 입력하세요.')
return
}
try {
const res = await fetch('/kngil/bbs/login.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id, pw })
})
console.log('login.js loaded')
const json = await res.json()
if (json.status === 'success') {
console.log('LOGIN OK, reload')
document.getElementById('pop_login').style.display = 'none'
location.reload()
} else {
alert(json.message)
}
} catch (err) {
console.error(err)
alert('로그인 중 오류가 발생했습니다.')
}
})
}
// OIDC 로그인 처리
const btnOidc = document.getElementById('btn_oidc_login')
if (btnOidc) {
btnOidc.addEventListener('click', () => {
const width = 500;
const height = 600;
const left = (window.screen.width / 2) - (width / 2);
const top = (window.screen.height / 2) - (height / 2);
window.open(
'/kngil/auth/oidc-login.php',
'oidc_login_popup',
`width=${width},height=${height},left=${left},top=${top},scrollbars=yes`
);
});
}
// 팝업으로부터의 메시지 수신 (로그인 성공 시 새로고침)
window.addEventListener('message', (event) => {
// 보안을 위해 실제 서비스에서는 event.origin을 체크하는 것이 좋습니다.
// if (event.origin !== location.origin) return;
if (event.data && event.data.type === 'OIDC_LOGIN_SUCCESS') {
location.reload();
}
});