From 67f2ac52edceb0263c107f2576dbf787e98a0108 Mon Sep 17 00:00:00 2001 From: Pheonix Date: Thu, 25 Jun 2026 12:34:24 +0530 Subject: [PATCH] added forgot password functionality --- frontend/src/pages/Auth/ForgotPAssword.jsx | 155 +++++++++++++++++++ frontend/src/pages/Auth/Login.jsx | 168 +++++++++++++-------- 2 files changed, 259 insertions(+), 64 deletions(-) create mode 100644 frontend/src/pages/Auth/ForgotPAssword.jsx diff --git a/frontend/src/pages/Auth/ForgotPAssword.jsx b/frontend/src/pages/Auth/ForgotPAssword.jsx new file mode 100644 index 0000000..45741e4 --- /dev/null +++ b/frontend/src/pages/Auth/ForgotPAssword.jsx @@ -0,0 +1,155 @@ +import React, { useState } from "react"; +import Input from "../../components/Inputs/Input"; +import Button from "../../components/Button/Button"; +import { validateEmail } from "../../utils/helper"; +import { API_PATHS } from "../../utils/apiPaths"; +import axiosInstance from "../../utils/axiosinstance"; +import { LuArrowRight, LuArrowLeft } from "react-icons/lu"; + +const ForgotPassword = ({ setCurrentPage }) => { + const [email, setEmail] = useState(""); + const [error, setError] = useState(null); + const [success, setSuccess] = useState(false); + const [loading, setLoading] = useState(false); + + const handleSubmit = async (e) => { + e.preventDefault(); + + if (!validateEmail(email)) { + setError("Please enter a valid email address."); + return; + } + + setError(null); + setLoading(true); + + try { + await axiosInstance.post(API_PATHS.AUTH.FORGOT_PASSWORD, { email }); + + setSuccess(true); + setError(null); + } catch (err) { + if (err.response?.data?.message) { + setError(err.response.data.message); + } else { + setError("Failed to send reset link. Please try again."); + } + } finally { + setLoading(false); + } + }; + + return ( +
+
+ {/* Header */} +
+
+ PrepPilot Logo + PrepPilot +
+ +

+ Reset Password +

+

+ Enter your email and we'll send you a link to reset your password +

+
+ + {!success ? ( +
+
+ setEmail(target.value)} + label="Email Address" + placeholder="your@email.com" + type="email" + autoFocus + /> +
+ + {error && ( +
+

{error}

+
+ )} + + + +
+ +
+
+ ) : ( + /* Success State */ +
+
+ + + +
+ +

+ Check Your Email +

+

+ We've sent a password reset link to
+ {email} +

+ + +
+ )} +
+
+ ); +}; + +export default ForgotPassword; diff --git a/frontend/src/pages/Auth/Login.jsx b/frontend/src/pages/Auth/Login.jsx index 8fb0539..4ea9252 100644 --- a/frontend/src/pages/Auth/Login.jsx +++ b/frontend/src/pages/Auth/Login.jsx @@ -20,14 +20,23 @@ const Login = ({ setCurrentPage, onLoginSuccess }) => { const handleLogin = async (e) => { e.preventDefault(); - if (!validateEmail(email)) { setError("Please enter a valid email address."); return; } - if (!password) { setError("Please enter your password"); return; } + if (!validateEmail(email)) { + setError("Please enter a valid email address."); + return; + } + if (!password) { + setError("Please enter your password"); + return; + } setError(""); setLoading(true); try { - const response = await axiosInstance.post(API_PATHS.AUTH.LOGIN, { email, password }); + const response = await axiosInstance.post(API_PATHS.AUTH.LOGIN, { + email, + password, + }); const { token } = response.data; if (token) { @@ -56,44 +65,50 @@ const Login = ({ setCurrentPage, onLoginSuccess }) => { return (
-
- {/* Header */} -
-
- PrepPilot Logo - PrepPilot -
-

- Welcome Back -

-

Sign in to continue your interview preparation journey

+ {/* Header */} +
+
+ PrepPilot Logo + PrepPilot
+

+ Welcome Back +

+

+ Sign in to continue your interview preparation journey +

+
-
-
- setEmail(target.value)} - label="Email Address" - placeholder="your@email.com" - type="text" - autoFocus - /> -
+ +
+ setEmail(target.value)} + label="Email Address" + placeholder="your@email.com" + type="text" + autoFocus + /> +
-
- setPassword(target.value)} - label="Password" - placeholder="Min 8 characters" - type="password" - /> -
+
+ setPassword(target.value)} + label="Password" + placeholder="Min 8 characters" + type="password" + /> +
- {/* Remember Me */} -
+ {/* Remember Me + Forgot Password */} +
+
{ onChange={(e) => setRememberMe(e.target.checked)} className="cursor-pointer w-4 h-4 rounded border-gray-600 bg-white" /> -
- {error && ( - - )} - - + Forgot Password? + +
-
-

- Don't have an account?{" "} - -

+ {error && ( + - -
+ )} + + + +
+

+ Don't have an account?{" "} + +

+
+
+
); };