mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
Avoid user from setting the same old password
This commit is contained in:
@ -38,6 +38,24 @@ export default function ResetPassword(props: any) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
toast.dismiss();
|
||||||
|
|
||||||
|
if (response.status == 404) {
|
||||||
|
toast.error("Invalid Token");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status == 400) {
|
||||||
|
toast.error("New password must be different");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status == 500) {
|
||||||
|
toast.error("Something went wrong.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setResetSuccessful(true);
|
setResetSuccessful(true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { NextApiRequest, NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { sendResetPassword, sendResetPasswordSuccessMail } from "@documenso/lib/mail";
|
import { sendResetPassword } from "@documenso/lib/mail";
|
||||||
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
|
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
|
||||||
import prisma from "@documenso/prisma";
|
import prisma from "@documenso/prisma";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { NextApiRequest, NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { hashPassword } from "@documenso/lib/auth";
|
import { hashPassword, verifyPassword } from "@documenso/lib/auth";
|
||||||
import { sendResetPasswordSuccessMail } from "@documenso/lib/mail";
|
import { sendResetPasswordSuccessMail } from "@documenso/lib/mail";
|
||||||
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
|
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
|
||||||
import prisma from "@documenso/prisma";
|
import prisma from "@documenso/prisma";
|
||||||
@ -22,7 +22,15 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!foundToken) {
|
if (!foundToken) {
|
||||||
return res.status(400).json({ message: "Invalid token." });
|
return res.status(404).json({ message: "Invalid token." });
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSamePassword = await verifyPassword(password, foundToken.User.password!);
|
||||||
|
|
||||||
|
if (isSamePassword) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ message: "New password must be different from the current password." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const hashedPassword = await hashPassword(password);
|
const hashedPassword = await hashPassword(password);
|
||||||
|
|||||||
Reference in New Issue
Block a user