41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
window.onload = () => {
|
|
document.getElementById('username').focus();
|
|
}
|
|
|
|
function showPasswd() {
|
|
let x = document.getElementById("password");
|
|
if(x.type == "password"){
|
|
x.type = "text";
|
|
y.type = "text";
|
|
} else {
|
|
x.type = "password";
|
|
y.type = "password";
|
|
}
|
|
}
|
|
|
|
document.querySelector('form').addEventListener('submit', () => {
|
|
const username = document.getElementById('username').value;
|
|
localStorage.setItem('username', username);
|
|
})
|
|
|
|
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault()
|
|
const username = document.getElementById('username').value.trim();
|
|
const password = document.getElementById('password').value.trim();
|
|
const messageBox = document.getElementById('messageBox');
|
|
const jsonData = JSON.stringify({ username, password })
|
|
const response = await fetch ('/auth/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: jsonData
|
|
});
|
|
|
|
const result = await response.json();
|
|
if(response.ok) {
|
|
location.href='/chat';
|
|
} else {
|
|
messageBox.innerText = result.message;
|
|
}
|
|
}) |