Skip to content

Commit 0307aa0

Browse files
author
Uttam Singh
committed
Updated login to redirect to OTP forgot password page
1 parent dc38181 commit 0307aa0

File tree

3 files changed

+75
-16
lines changed

3 files changed

+75
-16
lines changed

frontend/src/pages/App.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ import React from "react";
22
import { BrowserRouter, Routes, Route } from "react-router-dom";
33
import Login from "./Login.jsx";
44
import Dashboard from "./Dashboard.jsx";
5-
import AdminDashboard from "./AdminDashboard.jsx"; // ✅ Import added
5+
import AdminDashboard from "./AdminDashboard.jsx";
6+
import ForgotPassword from "./ForgotPassword.jsx"; // ✅ added
67

78
export default function App() {
89
return (
910
<BrowserRouter>
1011
<Routes>
11-
{/* Default login page */}
1212
<Route path="/" element={<Login />} />
13-
14-
{/* Regular user dashboard */}
1513
<Route path="/dashboard" element={<Dashboard />} />
16-
17-
{/* ✅ Admin dashboard route */}
1814
<Route path="/admin-dashboard" element={<AdminDashboard />} />
15+
<Route path="/forgot-password" element={<ForgotPassword />} /> {/* ✅ added */}
1916
</Routes>
2017
</BrowserRouter>
2118
);
2219
}
20+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useState } from "react";
2+
3+
export default function ForgotPassword() {
4+
const [email, setEmail] = useState("");
5+
const [message, setMessage] = useState("");
6+
7+
const handleSubmit = async (e) => {
8+
e.preventDefault();
9+
try {
10+
const res = await fetch("https://fat-eibl-backend-x1sp.onrender.com/users/forgot-password", {
11+
method: "POST",
12+
headers: { "Content-Type": "application/json" },
13+
body: JSON.stringify({ email }),
14+
});
15+
const data = await res.json();
16+
setMessage(data.message || "If the email exists, OTP has been sent.");
17+
} catch (error) {
18+
setMessage("Something went wrong. Please try again.");
19+
}
20+
};
21+
22+
return (
23+
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-50">
24+
<h1 className="text-2xl font-semibold mb-4">Forgot Password</h1>
25+
<form onSubmit={handleSubmit} className="bg-white p-6 rounded shadow w-80">
26+
<input
27+
type="email"
28+
placeholder="Enter registered email"
29+
value={email}
30+
onChange={(e) => setEmail(e.target.value)}
31+
required
32+
className="border w-full p-2 mb-4 rounded"
33+
/>
34+
<button
35+
type="submit"
36+
className="bg-blue-600 text-white px-4 py-2 rounded w-full hover:bg-blue-700"
37+
>
38+
Send OTP
39+
</button>
40+
</form>
41+
{message && <p className="mt-4 text-green-600">{message}</p>}
42+
</div>
43+
);
44+
}

frontend/src/pages/Login.jsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default function Login() {
88
const [loading, setLoading] = useState(false);
99
const [error, setError] = useState("");
1010

11+
// ✅ Login function
1112
const handleSubmit = async (e) => {
1213
e.preventDefault();
1314
setLoading(true);
@@ -18,9 +19,7 @@ export default function Login() {
1819
"https://fat-eibl-backend-x1sp.onrender.com/users/login",
1920
{
2021
method: "POST",
21-
headers: {
22-
Accept: "application/json",
23-
},
22+
headers: { Accept: "application/json" },
2423
body: new URLSearchParams({
2524
email: email,
2625
password: password,
@@ -34,10 +33,10 @@ export default function Login() {
3433
setError(data.detail || "Invalid credentials");
3534
} else {
3635
alert(`Welcome ${data.user.name}!`);
37-
// Save user info to localStorage (for future dashboard use)
36+
// Save user info for session
3837
localStorage.setItem("user", JSON.stringify(data.user));
3938

40-
// Redirect based on role
39+
// Redirect based on role
4140
if (data.user.role === "admin") {
4241
window.location.href = "/admin-dashboard";
4342
} else {
@@ -51,9 +50,9 @@ export default function Login() {
5150
}
5251
};
5352

53+
// ✅ Forgot password redirect (no Outlook)
5454
const handleForgotPassword = () => {
55-
const mailtoLink = `mailto:[email protected]?subject=Forgot Password - FAT-EIBL&body=Dear Support,%0D%0A%0D%0AI forgot my password. Please help me reset it.%0D%0A%0D%0ARegistered Email: ${email}%0D%0A%0D%0AThank you.`;
56-
window.location.href = mailtoLink;
55+
window.location.href = "/forgot-password";
5756
};
5857

5958
return (
@@ -67,16 +66,22 @@ export default function Login() {
6766
backgroundColor: "#f5f9ff",
6867
}}
6968
>
69+
{/* ✅ Logo */}
7070
<img
7171
src={logo}
7272
alt="Company Logo"
7373
style={{ width: "120px", marginBottom: "20px" }}
7474
/>
75-
<h1 style={{ color: "#004aad" }}>Welcome to FAT-EIBL</h1>
76-
<p style={{ color: "#003b80", marginBottom: "30px" }}>
75+
76+
{/* ✅ Title */}
77+
<h1 style={{ color: "#004aad", marginBottom: "10px" }}>
78+
Welcome to FAT-EIBL
79+
</h1>
80+
<p style={{ color: "#003b80", marginBottom: "30px", textAlign: "center" }}>
7781
Finance Audit Tracker – Edme Insurance Brokers Limited
7882
</p>
7983

84+
{/* ✅ Login form */}
8085
<form
8186
onSubmit={handleSubmit}
8287
style={{
@@ -88,6 +93,7 @@ export default function Login() {
8893
textAlign: "center",
8994
}}
9095
>
96+
{/* Email field */}
9197
<input
9298
type="email"
9399
placeholder="Email"
@@ -102,6 +108,8 @@ export default function Login() {
102108
}}
103109
required
104110
/>
111+
112+
{/* Password field */}
105113
<input
106114
type="password"
107115
placeholder="Password"
@@ -117,12 +125,20 @@ export default function Login() {
117125
required
118126
/>
119127

128+
{/* Error message */}
120129
{error && (
121-
<p style={{ color: "red", fontSize: "0.9rem", marginBottom: "10px" }}>
130+
<p
131+
style={{
132+
color: "red",
133+
fontSize: "0.9rem",
134+
marginBottom: "10px",
135+
}}
136+
>
122137
{error}
123138
</p>
124139
)}
125140

141+
{/* Submit button */}
126142
<button
127143
type="submit"
128144
disabled={loading}
@@ -139,6 +155,7 @@ export default function Login() {
139155
{loading ? "Logging in..." : "Login"}
140156
</button>
141157

158+
{/* ✅ Forgot password redirect */}
142159
<p
143160
onClick={handleForgotPassword}
144161
style={{

0 commit comments

Comments
 (0)