feat: Refactor login page to include signup form and shared reCAPTCHA
This commit is contained in:
1 parent
c12859f146
commit
96783cfcaf
1 file changed
+132
-127
+132
-127
@@ -7,92 +7,33 @@
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<!-- Include Google reCAPTCHA API script -->
|
||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||
<title>Login - Behind the Desk</title>
|
||||
<title>Login / Signup - Behind the Desk</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item has-text-weight-bold" href="index.html"> <!-- Link back to index -->
|
||||
Behind the Desk
|
||||
</a>
|
||||
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</a>
|
||||
</div>
|
||||
<div id="navbarBasicExample" class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<a class="navbar-item" href="index.html"> <!-- Link back to index -->
|
||||
top 🔥
|
||||
</a>
|
||||
<a class="navbar-item" href="#">
|
||||
new
|
||||
</a>
|
||||
<a class="navbar-item" href="#">
|
||||
nearby
|
||||
</a>
|
||||
<a class="navbar-item" href="#">
|
||||
past
|
||||
</a>
|
||||
<a class="navbar-item" href="#">
|
||||
ask
|
||||
</a>
|
||||
<a class="navbar-item" href="#">
|
||||
show
|
||||
</a>
|
||||
<a class="navbar-item" href="#">
|
||||
submit
|
||||
</a>
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item">
|
||||
<a href="#">Login</a> <!-- Changed handle to Login link -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<body style="padding-top: 0;"> <!-- Remove navbar padding override -->
|
||||
<!-- Navbar Removed -->
|
||||
|
||||
<main class="section main-content">
|
||||
<div class="container">
|
||||
<div class="columns is-centered">
|
||||
<div class="columns"> <!-- Use standard columns for side-by-side -->
|
||||
<!-- Login Column -->
|
||||
<div class="column is-half">
|
||||
<h1 class="title has-text-centered">Login</h1>
|
||||
<div class="box">
|
||||
<form id="login-form">
|
||||
<div class="field">
|
||||
<label class="label" for="username">Username</label>
|
||||
<label class="label" for="login-username">Username</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" id="username" name="username" placeholder="Enter your username" required>
|
||||
<input class="input" type="text" id="login-username" name="username" placeholder="Enter your username" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="password">Password</label>
|
||||
<label class="label" for="login-password">Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" id="password" name="password" placeholder="Enter your password" required>
|
||||
<input class="input" type="password" id="login-password" name="password" placeholder="Enter your password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="confirm-password">Confirm Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" id="confirm-password" name="confirm-password" placeholder="Confirm your password" required>
|
||||
</div>
|
||||
<p class="help is-danger is-hidden" id="password-mismatch">Passwords do not match.</p>
|
||||
</div>
|
||||
|
||||
<!-- reCAPTCHA Widget -->
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<div class="g-recaptcha" data-sitekey="YOUR_RECAPTCHA_SITE_KEY"></div>
|
||||
<!-- IMPORTANT: Replace YOUR_RECAPTCHA_SITE_KEY with your actual site key -->
|
||||
</div>
|
||||
<p class="help is-danger is-hidden" id="recaptcha-error">Please complete the reCAPTCHA.</p>
|
||||
</div>
|
||||
<!-- Confirm Password removed from Login -->
|
||||
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
@@ -101,96 +42,160 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<p class="has-text-centered">
|
||||
Don't have an account? <a href="signup.html">Sign up</a>
|
||||
</p>
|
||||
</div> <!-- End Login Column -->
|
||||
|
||||
<!-- Signup Column -->
|
||||
<div class="column is-half">
|
||||
<h1 class="title has-text-centered">Sign Up</h1>
|
||||
<div class="box">
|
||||
<form id="signup-form">
|
||||
<div class="field">
|
||||
<label class="label" for="signup-username">Username</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" id="signup-username" name="username" placeholder="Choose a username" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="signup-email">Email</label>
|
||||
<div class="control">
|
||||
<input class="input" type="email" id="signup-email" name="email" placeholder="Enter your email" required>
|
||||
</div>
|
||||
<!-- Optional: Add help text for email format -->
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="signup-password">Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" id="signup-password" name="password" placeholder="Create a password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="signup-confirm-password">Confirm Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" id="signup-confirm-password" name="confirm-password" placeholder="Confirm your password" required>
|
||||
</div>
|
||||
<p class="help is-danger is-hidden" id="signup-password-mismatch">Passwords do not match.</p>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-link is-fullwidth">Sign Up</button> <!-- Use is-link or another color for distinction -->
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div> <!-- End Signup Column -->
|
||||
|
||||
</div> <!-- End columns -->
|
||||
|
||||
<!-- Shared reCAPTCHA -->
|
||||
<div class="columns is-centered">
|
||||
<div class="column is-half">
|
||||
<div class="field mt-4">
|
||||
<div class="control has-text-centered"> <!-- Center the reCAPTCHA -->
|
||||
<div class="g-recaptcha" data-sitekey="YOUR_RECAPTCHA_SITE_KEY" style="display: inline-block;"></div>
|
||||
<!-- IMPORTANT: Replace YOUR_RECAPTCHA_SITE_KEY with your actual site key -->
|
||||
</div>
|
||||
<p class="help is-danger is-hidden has-text-centered" id="recaptcha-error">Please complete the reCAPTCHA.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- End container -->
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="content has-text-centered">
|
||||
<p>
|
||||
Seen something today? Don’t let it go to waste. <a href="#">Submit it</a>.
|
||||
</p>
|
||||
<div class="footer-menu">
|
||||
<a href="#">Guidelines</a> |
|
||||
<a href="#">Tips</a> |
|
||||
<a href="#">Privacy</a> |
|
||||
<a href="#">DMCA</a>
|
||||
</div>
|
||||
<div class="search-box">
|
||||
<input type="text" placeholder="Search...">
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<!-- Footer Removed -->
|
||||
|
||||
<!-- Simple script to toggle mobile menu -->
|
||||
<!-- Updated script for both forms -->
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Navbar burger toggle
|
||||
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
|
||||
if ($navbarBurgers.length > 0) {
|
||||
$navbarBurgers.forEach( el => {
|
||||
el.addEventListener('click', () => {
|
||||
const target = el.dataset.target;
|
||||
const $target = document.getElementById(target);
|
||||
el.classList.toggle('is-active');
|
||||
$target.classList.toggle('is-active');
|
||||
});
|
||||
});
|
||||
}
|
||||
// Navbar burger toggle removed
|
||||
|
||||
// Basic form validation example (password match)
|
||||
const loginForm = document.getElementById('login-form');
|
||||
const passwordInput = document.getElementById('password');
|
||||
const confirmPasswordInput = document.getElementById('confirm-password');
|
||||
const passwordMismatchHelp = document.getElementById('password-mismatch');
|
||||
const signupForm = document.getElementById('signup-form');
|
||||
const recaptchaErrorHelp = document.getElementById('recaptcha-error');
|
||||
|
||||
// --- Login Form Validation ---
|
||||
if (loginForm) {
|
||||
loginForm.addEventListener('submit', function(event) {
|
||||
let isValid = true;
|
||||
// Basic validation (e.g., required fields handled by HTML5 'required')
|
||||
|
||||
// Check password match
|
||||
if (passwordInput.value !== confirmPasswordInput.value) {
|
||||
confirmPasswordInput.classList.add('is-danger');
|
||||
passwordMismatchHelp.classList.remove('is-hidden');
|
||||
isValid = false;
|
||||
event.preventDefault(); // Prevent submission
|
||||
} else {
|
||||
confirmPasswordInput.classList.remove('is-danger');
|
||||
passwordMismatchHelp.classList.add('is-hidden');
|
||||
}
|
||||
|
||||
// Check reCAPTCHA response (basic check, server-side validation is crucial)
|
||||
// Check reCAPTCHA
|
||||
const recaptchaResponse = grecaptcha.getResponse();
|
||||
if (recaptchaResponse.length === 0) {
|
||||
recaptchaErrorHelp.classList.remove('is-hidden');
|
||||
isValid = false;
|
||||
event.preventDefault(); // Prevent submission
|
||||
} else {
|
||||
recaptchaErrorHelp.classList.add('is-hidden');
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
// Optionally scroll to the first error or provide more feedback
|
||||
event.preventDefault(); // Prevent submission if invalid
|
||||
}
|
||||
// IMPORTANT: Remember to perform server-side validation for passwords and reCAPTCHA!
|
||||
// Add further login validation if needed
|
||||
// IMPORTANT: Remember server-side validation!
|
||||
});
|
||||
}
|
||||
|
||||
// --- Signup Form Validation ---
|
||||
if (signupForm) {
|
||||
const signupPasswordInput = document.getElementById('signup-password');
|
||||
const signupConfirmPasswordInput = document.getElementById('signup-confirm-password');
|
||||
const signupPasswordMismatchHelp = document.getElementById('signup-password-mismatch');
|
||||
|
||||
signupForm.addEventListener('submit', function(event) {
|
||||
let isValid = true;
|
||||
|
||||
// Check password match
|
||||
if (signupPasswordInput.value !== signupConfirmPasswordInput.value) {
|
||||
signupConfirmPasswordInput.classList.add('is-danger');
|
||||
signupPasswordMismatchHelp.classList.remove('is-hidden');
|
||||
isValid = false;
|
||||
} else {
|
||||
signupConfirmPasswordInput.classList.remove('is-danger');
|
||||
signupPasswordMismatchHelp.classList.add('is-hidden');
|
||||
}
|
||||
|
||||
// Check reCAPTCHA
|
||||
const recaptchaResponse = grecaptcha.getResponse();
|
||||
if (recaptchaResponse.length === 0) {
|
||||
recaptchaErrorHelp.classList.remove('is-hidden');
|
||||
isValid = false;
|
||||
} else {
|
||||
recaptchaErrorHelp.classList.add('is-hidden');
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
event.preventDefault(); // Prevent submission if invalid
|
||||
}
|
||||
// Add further signup validation if needed (email format, username availability via AJAX etc.)
|
||||
// IMPORTANT: Remember server-side validation!
|
||||
});
|
||||
|
||||
// Real-time password match check (optional)
|
||||
confirmPasswordInput.addEventListener('input', () => {
|
||||
if (passwordInput.value !== confirmPasswordInput.value) {
|
||||
confirmPasswordInput.classList.add('is-danger');
|
||||
passwordMismatchHelp.classList.remove('is-hidden');
|
||||
// Real-time password match check for signup (optional)
|
||||
signupConfirmPasswordInput.addEventListener('input', () => {
|
||||
if (signupPasswordInput.value !== signupConfirmPasswordInput.value) {
|
||||
signupConfirmPasswordInput.classList.add('is-danger');
|
||||
signupPasswordMismatchHelp.classList.remove('is-hidden');
|
||||
} else {
|
||||
confirmPasswordInput.classList.remove('is-danger');
|
||||
passwordMismatchHelp.classList.add('is-hidden');
|
||||
signupConfirmPasswordInput.classList.remove('is-danger');
|
||||
signupPasswordMismatchHelp.classList.add('is-hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Reset reCAPTCHA error on interaction (optional, improves UX)
|
||||
// This requires a more complex setup if using the invisible reCAPTCHA or explicit rendering.
|
||||
// For the simple checkbox version, clicking it usually suffices.
|
||||
// We can hide the error when either form attempts submission again.
|
||||
if(recaptchaErrorHelp){
|
||||
if(loginForm) loginForm.addEventListener('submit', () => recaptchaErrorHelp.classList.add('is-hidden'));
|
||||
if(signupForm) signupForm.addEventListener('submit', () => recaptchaErrorHelp.classList.add('is-hidden'));
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user