-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (46 loc) · 1.83 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Lưu thông tin đăng ký vào Local Storage
const registerForm = document.getElementById('register-form');
if (registerForm) {
registerForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const user = {
username,
email,
password,
};
// Lưu người dùng vào Local Storage
localStorage.setItem('user', JSON.stringify(user));
alert('Đăng ký thành công!');
window.location.href = 'dashboard.html'; // Chuyển đến trang chính
});
}
// Kiểm tra thông tin đăng nhập
const loginForm = document.getElementById('login-form');
let checklogin = true;
if (loginForm) {
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = document.getElementById('login-username').value;
const password = document.getElementById('login-password').value;
// Lấy người dùng từ Local Storage
const user = JSON.parse(localStorage.getItem('user'));
if (user && user.username === username && user.password === password) {
alert('Đăng nhập thành công!');
window.location.href = 'dashboard.html'; // Chuyển đến trang chính
checklogin = true;
} else {
alert('Tên đăng nhập hoặc mật khẩu không chính xác!');
checklogin = false;
}
});
}
const login_button = document.getElementsByClassName("login-btn");
if (checklogin == true){
login_button.innerHTML = `Đăng nhập`
}
else {
login_button.innerHTML = `Đăng xuất`
}