Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home page access without login. #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions html/home-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ <h2>we are happy to see you again!</h2>
</div>

<div style="display: flex; height: 100%; width: 100%; justify-content: center; align-items: center;">
<a href="../html/icy-tower-home.html" class="game"><img class="icy-img" src="../image/icy-tower-start1.png" style="margin-top: 50px; width: 40vw;"></a>
</div>
<a href="../html/icy-tower-home.html" class="game" id="start-game-link">
<img class="icy-img" src="../image/icy-tower-start1.png" style="margin-top: 50px; width: 40vw;">
</a>
</div>


<script src="../js/login-sign-in.js"></script>
</body>
Expand Down
62 changes: 52 additions & 10 deletions js/login-sign-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -233,4 +235,44 @@ function updateHeloUser() {
helloUser.classList.remove('hide');

toggleImageOpacity(true);
}
}


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
}