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

Added "remember me" to the signup and signin page connecting it to the local storage database for user authentication. #750

Open
wants to merge 3 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: 6 additions & 1 deletion SignUp/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ <h1>Create Your Account</h1>
<input type="password" id="confirm-password" name="confirm-password" placeholder="Re-enter password" required>
<i class="bi bi-eye" id="toggleConfirmPassword" aria-label="Toggle confirm password visibility"></i>
</div>
<div id="password-error" class="error-message"></div>
<div id="password-error" class="error-message"></div> <!-- Password error container -->
<div class="input-group">
<label for="remember-me">
<input type="checkbox" id="remember-me" name="remember-me"> Remember Me
</label>
</div>
<button type="submit" class="signup-button">Sign Up</button>
</form>
<div class="or-divider">
Expand Down
39 changes: 39 additions & 0 deletions SignUp/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,45 @@ document.addEventListener("DOMContentLoaded", () => {
registerUser(userdata);
});

document.addEventListener("DOMContentLoaded", function () {
const rememberMeCheckbox = document.getElementById("remember-me");

// Load the Remember Me state from local storage
rememberMeCheckbox.checked = localStorage.getItem("rememberMe") === "true";

// Handle form submission
document.querySelector("form").addEventListener("submit", function (event) {
event.preventDefault();

// Save Remember Me state in local storage
localStorage.setItem("rememberMe", rememberMeCheckbox.checked);

// Retrieve form data
const formData = {
username: document.getElementById("username").value,
email: document.getElementById("email").value,
password: document.getElementById("password").value,
rememberMe: rememberMeCheckbox.checked
};

// Send form data to the server (example AJAX call, replace URL with your endpoint)
fetch('/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
});
});

const registerUser = async (user) => {
try {
const res = await fetch("http://localhost:5000/auth/signup", {
Expand Down
6 changes: 5 additions & 1 deletion login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ <h1 class="login-title">Welcome to Gaming Tools Store!</h1>
<input type="password" id="password" placeholder="Enter your password" required>
<i class="bi bi-eye" id="togglePassword" aria-label="Toggle password visibility"></i>
</div>

<div>
<label for="remember-me">
<input type="checkbox" id="remember-me" name="remember-me"> Remember Me
</label>
</div>
<button type="submit" class="login-button">Login</button>
<button id='google-login-btn' type="button">Login with Google</button>
</form>
Expand Down