Skip to content

Commit

Permalink
New code!
Browse files Browse the repository at this point in the history
  • Loading branch information
NhatQuyenIT committed Dec 3, 2023
1 parent af9002f commit 054d8dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ <h6 class="dropdown-item disabled">Danh mục</h6>
<li class="nav-item pt-2">
<button onClick="showform()"><i class="fa fa-user-circle-o" aria-hidden="true"></i> Tài khoản </button>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Giỏ hàng</a>
<li class="nav-item pt-2">
<button onClick="location.href='cart.html'"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Giỏ hàng</button>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
Expand Down
40 changes: 16 additions & 24 deletions js/MyJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,25 @@ function login(e) {
if (password == userArray[i].password) {
closeform();
localStorage.setItem('userlogin', JSON.stringify(userArray[i]));
window.location.reload(true);
updateUIAfterLogin(); // Thêm hàm này để cập nhật giao diện
return true;
}
}
}
}
document.getElementById('passwordloginerror').style.display = 'block';
document.getElementById('passwordloginerror').innerHTML = 'Sai thông tin đăng nhập';
return false;
}
function updateUIAfterLogin() {
var user = JSON.parse(localStorage.getItem('userlogin'));
var s = '<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Giỏ hàng</button></li>';
document.querySelector('#nav .topnav ul.right').innerHTML = s;
}
window.onload = function () {
checklogin(); // Thêm dòng này để kiểm tra đăng nhập khi tải trang
// ... (Các dòng mã khác)
}

function logout(url) {
localStorage.removeItem('userlogin');
Expand All @@ -192,35 +202,17 @@ function logout(url) {
function checklogin() {
if (localStorage.getItem('userlogin')) {
var user = JSON.parse(localStorage.getItem('userlogin'));
var s = '';
if (user.username == 'admin') {
s = '<li><button onClick="window.location.href=\'admin/product.html\'"><img src="images/icon/settings.svg"></button></li>' +
'<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><img src="images/icon/carticon.svg"></button></li>' +
'<li><button onClick="showSearch()"><img src="images/icon/searchicon.svg"></button></li>';
} else {
s = '<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><img src="images/icon/carticon.svg"></button></li>' +
'<li><button onClick="showSearch()"><img src="images/icon/searchicon.svg"></button></li>';
}
var s = '<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Giỏ hàng</button></li>';
document.querySelector('#nav .topnav ul.right').innerHTML = s;
}
}

function checklogin2() {
if (localStorage.getItem('userlogin')) {
var user = JSON.parse(localStorage.getItem('userlogin'));
var s = '';
if (user.username == 'admin') {
s = '<li><button onClick="window.location.href=\'../admin/product.html\'"><img src="../images/icon/settings.svg"></button></li>' +
'<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><img src="../images/icon/carticon.svg"></button></li>' +
'<li><button onClick="showSearch()"><img src="../images/icon/searchicon.svg"></button></li>';
} else {
s = '<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><img src="../images/icon/carticon.svg"></button></li>' +
'<li><button onClick="showSearch()"><img src="../images/icon/searchicon.svg"></button></li>';
}
var s = '<li><button>' + user.fullname + '</button><button id="btnlogout" onClick="logout(\'index.html\')">LOGOUT</button></li>' +
'<li><button onClick="location.href=\'cart.html\'"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Giỏ hàng</button></li>';
document.querySelector('#nav .topnav ul.right').innerHTML = s;
}
}
Expand Down

0 comments on commit 054d8dd

Please sign in to comment.