Skip to content

Commit fc1ea77

Browse files
authored
Merge pull request #50 from dipesh-2874/issue-46-regarding-signin-signup
Issue 46 regarding signin signup
2 parents 634e353 + f74c259 commit fc1ea77

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

auth.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,22 @@ if (signupForm) {
269269
return;
270270
}
271271

272-
window.location.href = getMainPagePath("signin.html");
272+
// if username already exists
273+
const userExists = users.some(user => user.email === email);
274+
275+
if (userExists) {
276+
error.textContent = "User already exists!";
277+
return;
278+
}
279+
280+
// new user
281+
const newUser = { username, email, password };
282+
users.push(newUser);
283+
localStorage.setItem("users", JSON.stringify(users));
284+
285+
localStorage.setItem("loggedIn", "true");
286+
localStorage.setItem("loggedInUser", username);
287+
window.location.href = getMainPagePath("index.html");
273288
});
274289
}
275290

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html lang="en">
33

44
<head>
@@ -168,12 +168,12 @@ <h3>Tic Tac Toe</h3>
168168

169169
<!-- AUTH SYSTEM -->
170170
<script src="auth.js"></script>
171+
<script src="script.js"></script>
171172
<script>
172173
checkAuth(); // protect page
173174
showLoggedInUser(); // show username
174175
</script>
175176

176-
<script src="script.js"></script>
177177

178178
</body>
179179

signin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ <h2>Login</h2>
3838
}
3939
</script>
4040
</body>
41-
</html>
41+
</html>

signup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ <h2>Create Account</h2>
4747
}
4848
</script>
4949
</body>
50-
</html>
50+
</html>

0 commit comments

Comments
 (0)