Chỉnh sửa hộp thoại đăng nhập
This commit is contained in:
+37
-6
@@ -285,11 +285,17 @@ function checkAuthStatus() {
|
||||
* Handles user login
|
||||
*/
|
||||
async function handleLogin() {
|
||||
const errorMsg = document.getElementById('login-error-msg');
|
||||
if (errorMsg) errorMsg.style.display = 'none';
|
||||
|
||||
const username = document.getElementById('username-input').value.trim();
|
||||
const password = document.getElementById('password-input').value.trim();
|
||||
|
||||
if (!username || !password) {
|
||||
alert('Please fill in both fields');
|
||||
if (errorMsg) {
|
||||
errorMsg.innerText = 'Vui lòng nhập đầy đủ thông tin';
|
||||
errorMsg.style.display = 'block';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -301,7 +307,7 @@ async function handleLogin() {
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.message || 'Login failed');
|
||||
if (!response.ok) throw new Error(data.message || 'Đăng nhập thất bại');
|
||||
|
||||
localStorage.setItem('jwt', data.token);
|
||||
localStorage.setItem('username', data.user.username);
|
||||
@@ -311,9 +317,15 @@ async function handleLogin() {
|
||||
checkAuthStatus();
|
||||
toggleDropdown(); // Đóng dropdown sau khi đăng nhập
|
||||
loadScenes(); // Reload scenes to show member/private scenes
|
||||
alert('Logged in successfully!');
|
||||
|
||||
// Làm sạch form
|
||||
document.getElementById('username-input').value = '';
|
||||
document.getElementById('password-input').value = '';
|
||||
} catch (error) {
|
||||
alert(error.message);
|
||||
if (errorMsg) {
|
||||
errorMsg.innerText = error.message;
|
||||
errorMsg.style.display = 'block';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,6 +357,22 @@ async function handleRegister() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hiển thị hộp thoại xác nhận đăng xuất
|
||||
*/
|
||||
function showLogoutConfirm() {
|
||||
const modal = document.getElementById('logout-confirm-modal');
|
||||
if (modal) modal.style.display = 'flex';
|
||||
}
|
||||
|
||||
/**
|
||||
* Đóng hộp thoại xác nhận đăng xuất
|
||||
*/
|
||||
function closeLogoutConfirm() {
|
||||
const modal = document.getElementById('logout-confirm-modal');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles user logout
|
||||
*/
|
||||
@@ -363,9 +391,12 @@ function handleLogout() {
|
||||
}
|
||||
|
||||
checkAuthStatus();
|
||||
toggleDropdown(); // Đóng dropdown sau khi đăng xuất
|
||||
if (document.getElementById('user-dropdown').classList.contains('show')) {
|
||||
toggleDropdown();
|
||||
}
|
||||
closeLogoutConfirm();
|
||||
closeDashboard();
|
||||
loadScenes(); // Reload scenes to filter out private ones
|
||||
alert('Logged out successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user