Loginv2
This commit is contained in:
15
script.js
15
script.js
@@ -2,6 +2,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const loginForm = document.querySelector('.login-form');
|
||||
const emailInput = document.getElementById('email');
|
||||
const passwordInput = document.getElementById('password');
|
||||
const confirmPasswordInput = document.getElementById('confirm-password');
|
||||
const confirmPasswordGroup = document.getElementById('confirm-password-group');
|
||||
const submitBtn = document.querySelector('.btn-primary');
|
||||
const btnText = submitBtn.querySelector('span');
|
||||
const helperText = document.querySelector('.signup-link');
|
||||
@@ -26,11 +28,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
subtitle.innerText = 'Enter your details below';
|
||||
btnText.innerText = 'Sign In';
|
||||
helperText.innerHTML = 'Don\'t have an account? <a href="#">Create One</a>';
|
||||
confirmPasswordGroup.classList.add('hidden');
|
||||
confirmPasswordInput.required = false;
|
||||
} else {
|
||||
title.innerText = 'Create Account';
|
||||
subtitle.innerText = 'Start your journey with us';
|
||||
btnText.innerText = 'Sign Up';
|
||||
helperText.innerHTML = 'Already have an account? <a href="#">Sign In</a>';
|
||||
confirmPasswordGroup.classList.remove('hidden');
|
||||
confirmPasswordInput.required = true;
|
||||
}
|
||||
|
||||
// Re-attach listener to the new link element
|
||||
@@ -77,6 +83,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const email = emailInput.value.trim();
|
||||
const password = passwordInput.value.trim();
|
||||
const confirmPassword = confirmPasswordInput.value.trim();
|
||||
const timestamp = new Date().toISOString();
|
||||
|
||||
// Get existing users
|
||||
@@ -97,12 +104,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
} else {
|
||||
// --- SIGNUP LOGIC ---
|
||||
// Check if user already exists
|
||||
// 1. Check if user already exists
|
||||
if (existingUsers.some(u => u.email === email)) {
|
||||
showFeedback(false, 'User exists');
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Validate Password Match
|
||||
if (password !== confirmPassword) {
|
||||
showFeedback(false, 'Passwords do not match');
|
||||
return;
|
||||
}
|
||||
|
||||
const newUser = { email, password, joinedAt: timestamp };
|
||||
existingUsers.push(newUser);
|
||||
localStorage.setItem('socialAppUsers', JSON.stringify(existingUsers));
|
||||
|
||||
Reference in New Issue
Block a user