From 061270633c39b72c29e93bc45b8fa15bd6609246 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 6 Apr 2021 21:14:08 -0300 Subject: [PATCH 1/2] feat: fga-eps-mds/2020.2-Lend.it#121 include nodeMailer. Co-authored-by: Thais Reboucas Co-authored-by: Vinicius Saturnino --- package-lock.json | 5 +++++ package.json | 1 + 2 files changed, 6 insertions(+) diff --git a/package-lock.json b/package-lock.json index bc5ed02..118f056 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5127,6 +5127,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 8cd9566..dc756f0 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", "pg": "^8.5.1", "pg-hstore": "^2.3.3", "sequelize": "^6.5.0" From 64f38b7e1d27f3ef17ace0ee499a7717903071f1 Mon Sep 17 00:00:00 2001 From: Thais-ra Date: Thu, 8 Apr 2021 23:00:58 -0300 Subject: [PATCH 2/2] feat: fga-eps-mds/2020.2-Lend.it#128 Add route update password Co-authored-by: Matheus Monteiro Co-authored-by: Vinicius Saturnino Co-authored-by: Youssef Muhamad --- src/controllers/UserController.js | 25 +++++++++++++++++++++++++ src/routes/user.routes.js | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/controllers/UserController.js b/src/controllers/UserController.js index c82a1ac..a2f3db6 100644 --- a/src/controllers/UserController.js +++ b/src/controllers/UserController.js @@ -75,4 +75,29 @@ export default { return response.status(500).json({ error: error.message }); } }, + + async update(request, response) { + const { oldPassword, newPassword, useremail } = request.body; + const user = await User.findOne({ + where: { + useremail, + }, + }); + + 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 }); + } + return response.status(200); + }, }; diff --git a/src/routes/user.routes.js b/src/routes/user.routes.js index 3ebb953..d29b30a 100644 --- a/src/routes/user.routes.js +++ b/src/routes/user.routes.js @@ -10,4 +10,6 @@ userRouter.get('/:useremail', UserController.show); userRouter.post('/', UserController.create); +userRouter.put('/', UserController.update); + export default userRouter;