+
Confirm Logout
+
+ Are you sure you want to log out of your account?
+
diff --git a/frontend/src/components/Pages/ResetPassword.jsx b/frontend/src/components/Pages/ResetPassword.jsx
index 3ed75422..6269c461 100644
--- a/frontend/src/components/Pages/ResetPassword.jsx
+++ b/frontend/src/components/Pages/ResetPassword.jsx
@@ -18,11 +18,28 @@ const ResetPassword = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
+ // Helper function for email validation
+ const isValidEmail = (email) => {
+ // Basic email regex, consider using a more robust solution in production
+ return /\S+@\S+\.\S+/.test(email);
+ };
+
const handleSubmit = async (e) => {
e.preventDefault();
setIsLoading(true);
setError(null);
+ // Add input validation // Basic validation examples
+ if (!isValidEmail(data.email)) {
+ setError("Please enter a valid email address");
+ return;
+ }
+
+ if (data.password.length < 8) {
+ setError("Password must be at least 8 characters long");
+ return;
+ }
+
const passwordMatch = data.password === data.confirmPassword;
if (!passwordMatch) {
setError("Passwords do not match");
@@ -79,6 +96,8 @@ const ResetPassword = () => {
name="email"
placeholder="Email"
type="email"
+ aria-required="true"
+ autoComplete="email"
onChange={(e) => handleChange(e)}
/>
diff --git a/frontend/src/components/Pages/Signup.jsx b/frontend/src/components/Pages/Signup.jsx
index b5105c6f..11cb8808 100644
--- a/frontend/src/components/Pages/Signup.jsx
+++ b/frontend/src/components/Pages/Signup.jsx
@@ -1,30 +1,73 @@
import { useState } from "react";
import photo from "../../assets/login.png";
+import { useNavigate } from "react-router-dom";
const Signup = () => {
- const [data, setData] = useState({
- name: "",
- email: "",
- password: "",
- });
+ const navigate = useNavigate();
+ const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState(null);
+ const [data, setData] = useState({
+ name: "",
+ email: "",
+ password: "",
+ });
- const handleChange = (e) => {
- setData({ ...data, [e.target.name]: e.target.value });
- };
+ const handleChange = (e) => {
+ setData({ ...data, [e.target.name]: e.target.value });
+ };
- const handleSubmit = async (e) => {
- e.preventDefault();
- console.log(data);
- const response = await fetch("http://localhost:3000/api/user/register", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(data),
- });
- const result = await response.json();
- console.log(result);
- };
+ const handleSubmit = async (e) => {
+ e.preventDefault();
+ setIsLoading(true);
+ // Add input validation
+ if (!data.email || !data.password || !data.name) {
+ setError("Please fill in all fields");
+ setIsLoading(false);
+ return;
+ }
+
+ if (data.password.length < 8) {
+ setError("Password must be at least 8 characters long");
+ setIsLoading(false);
+ return;
+ }
+
+ if (data.name.length < 3) {
+ setError("Name must be at least 3 characters long");
+ setIsLoading(false);
+ return;
+ }
+
+ if (!data.email.includes("@")) {
+ setError("Please enter a valid email address");
+ setIsLoading(false);
+ return;
+ }
+
+ try {
+ const response = await fetch("http://localhost:3000/api/user/register", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(data),
+ });
+ const result = await response.json();
+
+ if (!response.ok) {
+ setIsLoading(false);
+ setError(result.error);
+ return;
+ }
+
+ // Handle successful registration
+ alert("Registered successfully! Please log in.");
+ navigate("/");
+ } catch (error) {
+ setError(error.message);
+ console.error("Error:", error);
+ }
+ };
return (
@@ -43,8 +86,8 @@ const Signup = () => {
name="name"
placeholder="Name"
type="name"
+ aria-required="true"
onChange={(e) => handleChange(e)}
-
/>
{
type="password"
onChange={(e) => handleChange(e)}
/>
-
-
handleSubmit(e)}
+ {error && (
+
+ {error}
+
+ )}
+ handleSubmit(e)}
>
- Let’s go →
+ {isLoading ? "Loading..." : "Let's go →"}
From c2bec1ea049d8067bd97a1e4f677099561f1d4fd Mon Sep 17 00:00:00 2001
From: Samarth Vaidya
Date: Wed, 9 Oct 2024 19:44:37 +0530
Subject: [PATCH 8/9] code rabbit changes 2.0
---
frontend/src/components/Pages/Login.jsx | 6 +++---
frontend/src/components/Pages/ResetPassword.jsx | 3 ++-
frontend/src/components/Pages/Signup.jsx | 3 ++-
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/frontend/src/components/Pages/Login.jsx b/frontend/src/components/Pages/Login.jsx
index 135fdf29..63d1d984 100644
--- a/frontend/src/components/Pages/Login.jsx
+++ b/frontend/src/components/Pages/Login.jsx
@@ -1,6 +1,7 @@
import { Link, useNavigate } from "react-router-dom";
import photo from "../../assets/login.png";
import React, { useState } from "react";
+import { message } from "antd";
const Login = () => {
const API_URL = import.meta.env.VITE_BACKEND_URL || "http://localhost:3000";
@@ -32,10 +33,9 @@ const Login = () => {
if (!response.ok) {
throw new Error(result.message || "Login failed");
}
- console.log(result);
// Handle successful login (e.g., store token, redirect)
- alert("Login successful");
- navigate("/profile");
+ message.success("Login successful");
+ navigate("/");
} catch (err) {
setError(err.message || "An error occurred. Please try again.");
} finally {
diff --git a/frontend/src/components/Pages/ResetPassword.jsx b/frontend/src/components/Pages/ResetPassword.jsx
index 6269c461..802ecd06 100644
--- a/frontend/src/components/Pages/ResetPassword.jsx
+++ b/frontend/src/components/Pages/ResetPassword.jsx
@@ -1,6 +1,7 @@
import { Link, useNavigate } from "react-router-dom";
import photo from "../../assets/login.png";
import React, { useState } from "react";
+import { message } from "antd";
const ResetPassword = () => {
const API_URL = import.meta.env.VITE_BACKEND_URL || "http://localhost:3000";
@@ -61,7 +62,7 @@ const ResetPassword = () => {
}
// Display success message and navigate to login
- alert("Password reset successfully! Please log in.");
+ message.success("Password reset successfully! Please log in.");
navigate("/login");
} catch (err) {
setError(err.message);
diff --git a/frontend/src/components/Pages/Signup.jsx b/frontend/src/components/Pages/Signup.jsx
index 11cb8808..a7018615 100644
--- a/frontend/src/components/Pages/Signup.jsx
+++ b/frontend/src/components/Pages/Signup.jsx
@@ -3,6 +3,7 @@ import photo from "../../assets/login.png";
import { useNavigate } from "react-router-dom";
const Signup = () => {
+ const API_URL = import.meta.env.VITE_BACKEND_URL || "http://localhost:3000";
const navigate = useNavigate();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
@@ -45,7 +46,7 @@ const Signup = () => {
}
try {
- const response = await fetch("http://localhost:3000/api/user/register", {
+ const response = await fetch(`${API_URL}/api/user/register`, {
method: "POST",
headers: {
"Content-Type": "application/json",
From 2b44af9a8d93717887af163547547991e3ad2a36 Mon Sep 17 00:00:00 2001
From: Samarth Vaidya
Date: Wed, 9 Oct 2024 19:55:45 +0530
Subject: [PATCH 9/9] code rabbit changes 3.0
---
frontend/src/components/Pages/Signup.jsx | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/frontend/src/components/Pages/Signup.jsx b/frontend/src/components/Pages/Signup.jsx
index a7018615..000e5999 100644
--- a/frontend/src/components/Pages/Signup.jsx
+++ b/frontend/src/components/Pages/Signup.jsx
@@ -81,23 +81,26 @@ const Signup = () => {
Register to continue