// login.js (jQuery 버전) $(function () { const $loginForm = $('#loginForm'); const $alertBox = $('#alertBox'); const $submitBtn = $('#submitBtn'); const $rememberMeCheck = $('#rememberMe'); // 이미 로그인된 상태라면 처리 if (typeof isUserLoggedIn === 'function' && isUserLoggedIn()) { console.log('이미 로그인된 세션입니다. (login = 1)'); // window.location.href = './dashboard.html'; showAlert('이미 로그인된 상태입니다.', 'info'); } $loginForm.on('submit', function (e) { e.preventDefault(); const inputPassword = $('#password').val(); const keepLoggedIn = $rememberMeCheck.is(':checked'); if (!inputPassword) { showAlert('비밀번호를 입력해주세요.', 'danger'); return; } // 로딩 UI 설정 $submitBtn.prop('disabled', true) .html('인증 중...'); // jQuery AJAX로 password.bin 바이너리(ArrayBuffer) 요청 $.ajax({ url: hostURL+'/password.bin', type: 'GET', cache: false, xhrFields: { responseType: 'arraybuffer' // 이진 데이터를 ArrayBuffer로 수신 } }) .done(function (arrayBuffer) { // ArrayBuffer 바이너리 데이터를 UTF-8 텍스트로 디코딩 const decoder = new TextDecoder('utf-8'); const storedPassword = decoder.decode(arrayBuffer).trim(); if (inputPassword === storedPassword) { // 로그인 유지 설정 반영 setLoginStatus(1, keepLoggedIn); showAlert('인증에 성공했습니다. 로그인 상태가 유지됩니다.', 'success'); setTimeout(function () { console.log('현재 로그인 상태 (window.login):', window.login); // window.location.href = './dashboard.html'; }, 1000); } else { setLoginStatus(0); showAlert('비밀번호가 일치하지 않습니다.', 'danger'); } }) .fail(function (jqXHR, textStatus, errorThrown) { setLoginStatus(0); console.error('로그인 에러:', textStatus, errorThrown); showAlert('비밀번호 인증 데이터 파일을 불러올 수 없습니다.', 'danger'); }) .always(function () { // 버튼 상태 원복 $submitBtn.prop('disabled', false).text('로그인'); }); }); // 알림 메시지 표시 헬퍼 함수 function showAlert(message, type) { $alertBox .attr('class', `alert alert-${type} mt-3 text-center py-2`) .text(message) .removeClass('d-none'); } });