From 90564e6abcaf1e40c5f8f5aa4ef48141966c3d39 Mon Sep 17 00:00:00 2001 From: Cerebro-184 Date: Fri, 13 Mar 2026 00:11:18 +0530 Subject: [PATCH 1/3] false commit --- auth.js | 46 +++++++++++++++++++++++++++++++--------------- index.html | 2 +- signin.html | 2 +- signup.html | 2 +- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/auth.js b/auth.js index f42ba70..8c21405 100644 --- a/auth.js +++ b/auth.js @@ -28,8 +28,8 @@ if (signupForm) { signupForm.addEventListener("submit", (event) => { event.preventDefault(); - const username = document.getElementById("username").value; - const email = document.getElementById("email").value; + const username = document.getElementById("username").value.trim(); + const email = document.getElementById("email").value.trim(); const password = document.getElementById("password").value; const confirmPassword = document.getElementById("confirmPassword").value; const error = document.getElementById("signupError"); @@ -41,10 +41,25 @@ if (signupForm) { return; } - const user = { username, email, password }; - localStorage.setItem("user", JSON.stringify(user)); + // getting existing users + let users = JSON.parse(localStorage.getItem("users")) || []; - window.location.href = getMainPagePath("signin.html"); + // if username already exists + const userExists = users.some(user => user.email === email); + + if (userExists) { + error.textContent = "User already exists!"; + return; + } + + // new user + const newUser = { username, email, password }; + users.push(newUser); + localStorage.setItem("users", JSON.stringify(users)); + + localStorage.setItem("loggedIn", "true"); + localStorage.setItem("loggedInUser", username); + window.location.href = getMainPagePath("index.html"); }); } @@ -55,18 +70,19 @@ if (signinForm) { signinForm.addEventListener("submit", (event) => { event.preventDefault(); - const email = document.getElementById("loginEmail").value; + const email = document.getElementById("loginEmail").value.trim(); const password = document.getElementById("loginPassword").value; const error = document.getElementById("loginError"); - const storedUser = JSON.parse(localStorage.getItem("user")); - if ( - storedUser && - storedUser.email === email && - storedUser.password === password - ) { + const users = JSON.parse(localStorage.getItem("users")) || []; + + const user = users.find( + u => u.email === email && u.password === password + ); + + if (user) { localStorage.setItem("loggedIn", "true"); - localStorage.setItem("loggedInUser", storedUser.username); + localStorage.setItem("loggedInUser", user.username); window.location.href = getMainPagePath("index.html"); } else { error.textContent = "Invalid email or password"; @@ -86,8 +102,8 @@ function showLoggedInUser() { const username = localStorage.getItem("loggedInUser"); const userElement = document.getElementById("navUsername"); - if (userElement && username) { - userElement.textContent = username; + if (userElement) { + userElement.textContent = username ? username : "User"; } } diff --git a/index.html b/index.html index 6415c58..1f202f2 100644 --- a/index.html +++ b/index.html @@ -167,12 +167,12 @@

Tic Tac Toe

+ - diff --git a/signin.html b/signin.html index eb4608a..4d32b21 100644 --- a/signin.html +++ b/signin.html @@ -33,7 +33,7 @@

Login

diff --git a/signup.html b/signup.html index 9764c0d..71268e1 100644 --- a/signup.html +++ b/signup.html @@ -42,7 +42,7 @@

Create Account

From cf6a9798d1d0cff647890641205da3e3cdef1304 Mon Sep 17 00:00:00 2001 From: Cerebro-184 Date: Fri, 13 Mar 2026 00:13:59 +0530 Subject: [PATCH 2/3] true commit --- auth.js | 48 ++++++++++++++++-------------------------------- index.html | 4 ++-- signin.html | 4 ++-- signup.html | 4 ++-- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/auth.js b/auth.js index 8c21405..25ec070 100644 --- a/auth.js +++ b/auth.js @@ -28,8 +28,8 @@ if (signupForm) { signupForm.addEventListener("submit", (event) => { event.preventDefault(); - const username = document.getElementById("username").value.trim(); - const email = document.getElementById("email").value.trim(); + const username = document.getElementById("username").value; + const email = document.getElementById("email").value; const password = document.getElementById("password").value; const confirmPassword = document.getElementById("confirmPassword").value; const error = document.getElementById("signupError"); @@ -41,25 +41,10 @@ if (signupForm) { return; } - // getting existing users - let users = JSON.parse(localStorage.getItem("users")) || []; + const user = { username, email, password }; + localStorage.setItem("user", JSON.stringify(user)); - // if username already exists - const userExists = users.some(user => user.email === email); - - if (userExists) { - error.textContent = "User already exists!"; - return; - } - - // new user - const newUser = { username, email, password }; - users.push(newUser); - localStorage.setItem("users", JSON.stringify(users)); - - localStorage.setItem("loggedIn", "true"); - localStorage.setItem("loggedInUser", username); - window.location.href = getMainPagePath("index.html"); + window.location.href = getMainPagePath("signin.html"); }); } @@ -70,19 +55,18 @@ if (signinForm) { signinForm.addEventListener("submit", (event) => { event.preventDefault(); - const email = document.getElementById("loginEmail").value.trim(); + const email = document.getElementById("loginEmail").value; const password = document.getElementById("loginPassword").value; const error = document.getElementById("loginError"); + const storedUser = JSON.parse(localStorage.getItem("user")); - const users = JSON.parse(localStorage.getItem("users")) || []; - - const user = users.find( - u => u.email === email && u.password === password - ); - - if (user) { + if ( + storedUser && + storedUser.email === email && + storedUser.password === password + ) { localStorage.setItem("loggedIn", "true"); - localStorage.setItem("loggedInUser", user.username); + localStorage.setItem("loggedInUser", storedUser.username); window.location.href = getMainPagePath("index.html"); } else { error.textContent = "Invalid email or password"; @@ -102,8 +86,8 @@ function showLoggedInUser() { const username = localStorage.getItem("loggedInUser"); const userElement = document.getElementById("navUsername"); - if (userElement) { - userElement.textContent = username ? username : "User"; + if (userElement && username) { + userElement.textContent = username; } } @@ -112,4 +96,4 @@ function logout() { localStorage.removeItem("loggedIn"); localStorage.removeItem("loggedInUser"); window.location.href = getMainPagePath("signin.html"); -} +} \ No newline at end of file diff --git a/index.html b/index.html index 1f202f2..8c0bfac 100644 --- a/index.html +++ b/index.html @@ -167,13 +167,13 @@

Tic Tac Toe

- + - + \ No newline at end of file diff --git a/signin.html b/signin.html index 4d32b21..62d043c 100644 --- a/signin.html +++ b/signin.html @@ -33,8 +33,8 @@

Login

- + \ No newline at end of file diff --git a/signup.html b/signup.html index 71268e1..a7f9979 100644 --- a/signup.html +++ b/signup.html @@ -42,8 +42,8 @@

Create Account

- + \ No newline at end of file From 5d011eb1654a7dd1754d0d5f236bf156bd0c5b8a Mon Sep 17 00:00:00 2001 From: Cerebro-184 Date: Fri, 13 Mar 2026 00:18:49 +0530 Subject: [PATCH 3/3] Add: issue regarding signup and signin --- auth.js | 49 +++++++++++++++++++++++++++++++++---------------- index.html | 6 +++--- signin.html | 2 +- signup.html | 2 +- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/auth.js b/auth.js index 25ec070..5cf1de8 100644 --- a/auth.js +++ b/auth.js @@ -28,8 +28,8 @@ if (signupForm) { signupForm.addEventListener("submit", (event) => { event.preventDefault(); - const username = document.getElementById("username").value; - const email = document.getElementById("email").value; + const username = document.getElementById("username").value.trim(); + const email = document.getElementById("email").value.trim(); const password = document.getElementById("password").value; const confirmPassword = document.getElementById("confirmPassword").value; const error = document.getElementById("signupError"); @@ -41,10 +41,25 @@ if (signupForm) { return; } - const user = { username, email, password }; - localStorage.setItem("user", JSON.stringify(user)); + // getting existing users + let users = JSON.parse(localStorage.getItem("users")) || []; - window.location.href = getMainPagePath("signin.html"); + // if username already exists + const userExists = users.some(user => user.email === email); + + if (userExists) { + error.textContent = "User already exists!"; + return; + } + + // new user + const newUser = { username, email, password }; + users.push(newUser); + localStorage.setItem("users", JSON.stringify(users)); + + localStorage.setItem("loggedIn", "true"); + localStorage.setItem("loggedInUser", username); + window.location.href = getMainPagePath("index.html"); }); } @@ -55,18 +70,19 @@ if (signinForm) { signinForm.addEventListener("submit", (event) => { event.preventDefault(); - const email = document.getElementById("loginEmail").value; + const email = document.getElementById("loginEmail").value.trim(); const password = document.getElementById("loginPassword").value; const error = document.getElementById("loginError"); - const storedUser = JSON.parse(localStorage.getItem("user")); - if ( - storedUser && - storedUser.email === email && - storedUser.password === password - ) { + const users = JSON.parse(localStorage.getItem("users")) || []; + + const user = users.find( + u => u.email === email && u.password === password + ); + + if (user) { localStorage.setItem("loggedIn", "true"); - localStorage.setItem("loggedInUser", storedUser.username); + localStorage.setItem("loggedInUser", user.username); window.location.href = getMainPagePath("index.html"); } else { error.textContent = "Invalid email or password"; @@ -86,8 +102,8 @@ function showLoggedInUser() { const username = localStorage.getItem("loggedInUser"); const userElement = document.getElementById("navUsername"); - if (userElement && username) { - userElement.textContent = username; + if (userElement) { + userElement.textContent = username ? username : "User"; } } @@ -96,4 +112,5 @@ function logout() { localStorage.removeItem("loggedIn"); localStorage.removeItem("loggedInUser"); window.location.href = getMainPagePath("signin.html"); -} \ No newline at end of file +} + diff --git a/index.html b/index.html index 8c0bfac..37a26a7 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ - + @@ -167,13 +167,13 @@

Tic Tac Toe

+ - - \ No newline at end of file + diff --git a/signin.html b/signin.html index 62d043c..5e98d6d 100644 --- a/signin.html +++ b/signin.html @@ -33,7 +33,7 @@

Login

diff --git a/signup.html b/signup.html index a7f9979..ee0fac1 100644 --- a/signup.html +++ b/signup.html @@ -42,7 +42,7 @@

Create Account