diff --git a/package-lock.json b/package-lock.json index a89884a..37da753 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5413,6 +5413,11 @@ "integrity": "sha512-zR6HoT6LrLCRBwukmrVbHv0EpEQjksO6GmFcZQQuCAy139BEsoVKPYnf3jongYW83fAa1torLGYwxxky/p28sg==", "dev": true }, + "nodemailer": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.5.0.tgz", + "integrity": "sha512-Tm4RPrrIZbnqDKAvX+/4M+zovEReiKlEXWDzG4iwtpL9X34MJY+D5LnQPH/+eghe8DLlAVshHAJZAZWBGhkguw==" + }, "nodemon": { "version": "1.19.4", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.19.4.tgz", diff --git a/package.json b/package.json index 04521a4..fc77112 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "dotenv": "^8.2.0", "express": "^4.17.1", "jsonwebtoken": "^8.5.1", + "nodemailer": "^6.5.0", "multer": "^1.4.2", "pg": "^8.5.1", "pg-hstore": "^2.3.3", diff --git a/src/controllers/UserController.js b/src/controllers/UserController.js index b5373e1..079b640 100644 --- a/src/controllers/UserController.js +++ b/src/controllers/UserController.js @@ -114,6 +114,21 @@ export default { return response.status(404).json({ error: 'Usuário não existente' }); } + if (oldPassword && newPassword) { + if (!(await bcrypt.compare(oldPassword, user.password))) { + return response.status(400).json({ error: 'Senha Inválida!' }); + } + + const salt = bcrypt.genSaltSync(saltRounds); + const hashedPassword = bcrypt.hashSync(newPassword, salt); + + const updatedPassword = await user.update({ + password: hashedPassword, + }); + + return response.status(204).json({ updatedPassword }); + } + if (user.avatar) { const __dirname = path.resolve(); const avatarPath = path.resolve(