fix commit

This commit is contained in:
MuhammadKhalilzadeh
2024-06-28 13:46:05 +03:30
parent 6205a3385e
commit 318b62cd3b
2 changed files with 25 additions and 10 deletions
+1 -10
View File
@@ -237,7 +237,7 @@ const resetPasswordController = async (req, res, next) => {
const deleteUserController = async (req, res, next) => {
try {
// Validate user ID
// Validate user
await editUserParamValidation.validateAsync(req.params);
// Check if the user exists
@@ -268,12 +268,3 @@ module.exports = {
resetPasswordController,
deleteUserController,
};
module.exports = {
registerController,
loginController,
userEditController,
recoveryRequestController,
validateRecoveryTokenController,
resetPasswordController,
};
+24
View File
@@ -113,6 +113,29 @@ const deleteUser = async (req, res) => {
}
};
/**
* Request a recovery token
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @returns {Promise<UserModel>}
* @throws {Error}
*/
const requestRecoveryToken = async (req, res) => {
try {
// Delete any existing tokens
await RecoveryToken.deleteMany({ email: req.body.email });
let recoveryToken = new RecoveryToken({
email: req.body.email,
token: crypto.randomBytes(32).toString("hex"),
});
await recoveryToken.save();
return recoveryToken;
} catch (error) {
throw error;
}
};
const validateRecoveryToken = async (req, res) => {
try {
const candidateToken = req.body.recoveryToken;
@@ -495,6 +518,7 @@ module.exports = {
insertUser,
getUserByEmail,
updateUser,
deleteUser,
requestRecoveryToken,
validateRecoveryToken,
resetPassword,