Skip to content

Commit 5e1ae7a

Browse files
committed
Fix bugs
1 parent 5b1419f commit 5e1ae7a

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

backend/user-service/controller/user-controller.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ export const sendVerificationMail = async (
119119
}
120120

121121
const emailToken = crypto.randomBytes(16).toString("hex");
122-
await redisClient.set(email, emailToken, { EX: 60 * 5 }); // expire in 5 minutes
122+
await redisClient.set(`email_verification:${email}`, emailToken, {
123+
EX: 60 * 5,
124+
}); // expire in 5 minutes
123125
await sendMail(
124126
email,
125127
ACCOUNT_VERIFICATION_SUBJ,
@@ -152,7 +154,7 @@ export const verifyUser = async (
152154
return res.status(404).json({ message: `User ${email} not found` });
153155
}
154156

155-
const expectedToken = await redisClient.get(email);
157+
const expectedToken = await redisClient.get(`email_verification:${email}`);
156158

157159
if (expectedToken !== token) {
158160
return res
@@ -353,8 +355,16 @@ export const sendResetPasswordMail = async (
353355
return res.status(404).json({ message: `User not found` });
354356
}
355357

358+
if (!user.isVerified) {
359+
return res.status(403).json({
360+
message: "User is not verified. Please verify your account first.",
361+
});
362+
}
363+
356364
const emailToken = crypto.randomBytes(16).toString("hex");
357-
await redisClient.set(email, emailToken, { EX: 60 * 5 }); // expire in 5 minutes
365+
await redisClient.set(`password_reset:${email}`, emailToken, {
366+
EX: 60 * 5,
367+
}); // expire in 5 minutes
358368
await sendMail(
359369
email,
360370
RESET_PASSWORD_SUBJ,
@@ -387,7 +397,7 @@ export const resetPassword = async (
387397
return res.status(404).json({ message: `User not found` });
388398
}
389399

390-
const expectedToken = await redisClient.get(email);
400+
const expectedToken = await redisClient.get(`password_reset:${email}`);
391401

392402
if (expectedToken !== token) {
393403
return res
@@ -407,9 +417,7 @@ export const resetPassword = async (
407417
const updatedUser = await _updateUserPassword(email, hashedPassword);
408418

409419
if (!updatedUser) {
410-
return res
411-
.status(404)
412-
.json({ message: `User's password not reset.` });
420+
return res.status(404).json({ message: `User's password not reset.` });
413421
}
414422

415423
return res

backend/user-service/routes/user-routes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
verifyIsAdmin,
1919
verifyIsOwnerOrAdmin,
2020
} from "../middleware/basic-access-control";
21-
import { send } from "process";
2221

2322
const router = express.Router();
2423

frontend/src/pages/ForgetPassword/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const ForgetPassword: React.FC = () => {
105105
<TextField
106106
fullWidth
107107
margin="normal"
108-
label="Token"
108+
label="Token *"
109109
sx={(theme) => ({ marginTop: theme.spacing(1) })}
110110
{...registerPassword("token", {
111111
setValueAs: (value: string) => value.trim(),

0 commit comments

Comments
 (0)