diff --git a/html/home-page.html b/html/home-page.html index 2c4e96e..83cdbd2 100644 --- a/html/home-page.html +++ b/html/home-page.html @@ -102,8 +102,11 @@

we are happy to see you again!

- -
+ + + + + diff --git a/js/login-sign-in.js b/js/login-sign-in.js index a0e022d..a75b2f8 100644 --- a/js/login-sign-in.js +++ b/js/login-sign-in.js @@ -106,24 +106,26 @@ function checkLoginValidation(e) { let massege = document.querySelector('#error-massage'); let password = document.querySelector('#pwd').value; let userName = document.querySelector('#email').value; - console.log(userName); // Is this a debugging statement? let user = JSON.parse(localStorage.getItem(userName)); if (user == null || user.password != password) { - massege.classList.remove('hide'); - return; + massege.classList.remove('hide'); + return; } const currentUser = { - firstName: user['firstName'], - userName: userName, - highScore: user.highScore, - secondScore: user.secondScore, + firstName: user['firstName'], + userName: userName, + highScore: user.highScore, + secondScore: user.secondScore, }; sessionStorage.setItem('currentUser', JSON.stringify(currentUser)); massege.classList.add('hide'); - modalLogin.hide() - updateHeloUser(); + modalLogin.hide(); + + // Redirect to home page + window.location.href = "../html/icy-tower-home.html"; } + function checkEqualtoPwd() { let pw = document.querySelector('#pasword-first').value; if (pw != document.querySelector('#verify-pwd').value) { @@ -233,4 +235,44 @@ function updateHeloUser() { helloUser.classList.remove('hide'); toggleImageOpacity(true); -} \ No newline at end of file +} + + +const startGameLink = document.getElementById('start-game-link'); +const loginMessage = document.getElementById('you-must-login'); + +// Add event listener to the game link +startGameLink.addEventListener('click', (e) => { + if (sessionStorage.getItem('currentUser') === null) { + e.preventDefault(); + loginMessage.style.display = 'block'; + } +}); + +// Function to check login status and update the link's state +function checkLoginStatus() { + if (sessionStorage.getItem('currentUser') === null) { + startGameLink.style.pointerEvents = 'none'; + } else { + startGameLink.style.pointerEvents = 'auto'; + } +} + +// Call checkLoginStatus initially +checkLoginStatus(); + +// Assuming this function is called when the user logs in +function loginUser(username) { + // Simulate logging in + sessionStorage.setItem('currentUser', username); + + // Update the state of the link immediately after login + checkLoginStatus(); + + // Optionally, hide the login message + loginMessage.style.display = 'none'; + + // Redirect to the home page (or any other page) + window.location.href = '../html/icy-tower-home.html'; // Replace 'home.html' with your home page URL +} +