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

fix: Add Logout button #789

Merged
merged 4 commits into from
Jun 7, 2024
Merged
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
29 changes: 27 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
//}
// menuButton.forEach((button) => (button.onclick = () => closeNav()));


</script>


Expand Down Expand Up @@ -189,7 +188,8 @@ <h1>TourGuide . . .</h1>
<a href="loginPage.html" class="contact-btn"><button class="btn" id="btn-style" style="margin: 0;"
data-aos="fade-down">Login</button></a>


<a href="loginPage.html" class="contact-btn"><button class="btn" id="logout-btn" style="margin: 0; display: none;"
data-aos="fade-down" disabled>Log Out</button></a>

<!-- <a href="login-modified.html" class="contact-btn"><button class="btn" id="btn-style"
style="margin: 0; box-shadow:1.5px 1.5px 6px red;" data-aos="fade-down">Login</button></a> -->
Expand Down Expand Up @@ -1526,6 +1526,31 @@ <h4>Reach Out To Us</h4>
document.getElementById("year").innerHTML = new Date().getFullYear();
</script>

<script>
// Logout Button

document.addEventListener('DOMContentLoaded', function () {
var isLoggedIn = localStorage.getItem('isLoggedIn');
var loginButton = document.getElementById('btn-style');
var logoutButton = document.getElementById('logout-btn');

if (isLoggedIn === 'true') {
loginButton.style.display = 'none';
logoutButton.style.display = 'block';
loginButton.disabled = true ;
logoutButton.disabled = false;
logoutButton.style.cursor = 'pointer';
logoutButton.addEventListener('click', function() {
localStorage.setItem('isLoggedIn', 'false');
window.location.href = './index.html';
});
} else {
loginButton.style.display = 'block';
logoutButton.disabled = true;
}
});
</script>


</html><!-- New bubble background start -->

Expand Down
32 changes: 29 additions & 3 deletions loginPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<div class="content">
<h1>Welcome Back !</h1>
<p>Login with your personal information.</p>
<form action="">
<input type="email" name="" id="" placeholder="Email">
<input type="password" name="" id="" placeholder="Password">
<form action="" id="loginForm">
<input type="email" name="email" id="email" placeholder="Email" >
<input type="password" name="password" id="password" placeholder="Password">
<button type="submit" >Login</button>
</form>
<div class="passForget">Forgot your password?</div>
Expand All @@ -29,5 +29,31 @@ <h1>Welcome Back !</h1>
</div>

</div>

<script>

document.getElementById('loginForm').addEventListener('submit', function(event) {
event.preventDefault();

var email = document.getElementById('email').value;
var password = document.getElementById('password').value;

if (email.trim() === '' || password.trim() === '') {
localStorage.setItem('isLoggedIn', 'true');
alert('Please fill out all fields.');
} else {
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
localStorage.setItem('isLoggedIn', 'true');
alert('Please enter a valid email!');
} else {
localStorage.setItem('isLoggedIn', 'true');
alert('Login successful!');
window.location.href = './index.html';
}
}
});

</script>
</body>
</html>
Loading