fix commit

This commit is contained in:
MuhammadKhalilzadeh committed 2024-06-28 13:46:05 +03:30
1 parent 6205a3385e
commit 318b62cd3b
2 files changed
+25 -10

No files matched your search

+1 -10
View File
@@ -237,7 +237,7 @@ const resetPasswordController = async (req, res, next) => {
const deleteUserController = async (req, res, next) => { const deleteUserController = async (req, res, next) => {
try { try {
// Validate user ID // Validate user
await editUserParamValidation.validateAsync(req.params); await editUserParamValidation.validateAsync(req.params);
// Check if the user exists // Check if the user exists
@@ -268,12 +268,3 @@ module.exports = {
resetPasswordController, resetPasswordController,
deleteUserController, 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) => { const validateRecoveryToken = async (req, res) => {
try { try {
const candidateToken = req.body.recoveryToken; const candidateToken = req.body.recoveryToken;
@@ -495,6 +518,7 @@ module.exports = {
insertUser, insertUser,
getUserByEmail, getUserByEmail,
updateUser, updateUser,
deleteUser,
requestRecoveryToken, requestRecoveryToken,
validateRecoveryToken, validateRecoveryToken,
resetPassword, resetPassword,