diff --git a/assets/js/login.js b/assets/js/login.js new file mode 100644 index 0000000..4e332d1 --- /dev/null +++ b/assets/js/login.js @@ -0,0 +1,44 @@ +document.addEventListener('DOMContentLoaded', function() { + let nickname, password; + + function handleSubmit(event) { + event.preventDefault(); + + nickname = document.getElementById('nickname').value; + password = document.getElementById('password').value; + + pageStatusUpdate(); + } + + function pageStatusUpdate() { + const req = { + nickname, + password + }; + + + const apiUrl = 'http://127.0.0.1:1025/login'; + fetch(apiUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(req) + }) + .then(response => { + if (response.ok) { + return response.json(); + } + }) + .then(data => { + if (data && data.status === 0) { + window.location.href = '/list-rooms'; + } + }); + } + + const form = document.querySelector('form'); + form.addEventListener('submit', handleSubmit); + + setInterval(pageStatusUpdate, 1000); +}); \ No newline at end of file