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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions SignUp/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ <h1>Create Your Account</h1>
<input type="password" id="confirm-password" name="confirm-password" placeholder="Re-enter password" required>
</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 @@ -57,6 +57,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
5 changes: 5 additions & 0 deletions login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ <h1 class="login-title">Welcome to Gaming Tools Store!</h1>
<input type="password" id="password" placeholder="Enter your password" required>
<i class="far fa-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>
</form>
<div class="links">
Expand Down
Loading