mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-14 21:59:42 -06:00
Merge pull request #128 from bluewave-labs/feat/password-check
ACheck for new password different than old password. Fixed typo in r…
This commit is contained in:
2
Client/src/Components/Notifications/notify.js
Normal file
2
Client/src/Components/Notifications/notify.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import { toast } from "react-toastify";
|
||||
export default (message) => toast(message);
|
||||
@@ -40,10 +40,10 @@ const SetNewPassword = () => {
|
||||
...form,
|
||||
recoveryToken: token,
|
||||
});
|
||||
navigate("/new-passsword-confirmed");
|
||||
navigate("/new-password-confirmed");
|
||||
} catch (error) {
|
||||
// TODO display error (Toast?)
|
||||
alert(error);
|
||||
alert(error.response.data.msg);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
@@ -131,10 +131,16 @@ const validateRecoveryToken = async (req, res) => {
|
||||
const resetPassword = async (req, res) => {
|
||||
try {
|
||||
const newPassword = req.body.password;
|
||||
|
||||
// Validate token again
|
||||
const recoveryToken = await validateRecoveryToken(req, res);
|
||||
const user = await UserModel.findOne({ email: recoveryToken.email });
|
||||
|
||||
const match = await user.comparePassword(newPassword);
|
||||
if (match === true) {
|
||||
throw new Error("New password must be different from old password");
|
||||
}
|
||||
|
||||
if (user !== null) {
|
||||
user.password = newPassword;
|
||||
await user.save();
|
||||
|
||||
Reference in New Issue
Block a user