Skip to content

Commit

Permalink
Merge pull request #12 from Lend-it/128_editar_senha
Browse files Browse the repository at this point in the history
Solve #128 Editar Senha
  • Loading branch information
youssef-md authored Apr 16, 2021
2 parents b2b4228 + 4b6f9c7 commit 04fa29a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions src/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 04fa29a

Please sign in to comment.