update user

This commit is contained in:
Le Viet
2022-03-15 16:53:48 +07:00
parent 870e5b089e
commit 4e8d728142
4 changed files with 386 additions and 242 deletions
+46
View File
@@ -213,6 +213,52 @@ module.exports = {
});
},
updateProfile(username, data) {
return Member
.update(data,
{
returning: true,
where: {
username: username
}
}
)
.then(([rowsUpdate, [updatedRow]]) => {
return updatedRow
})
.catch(error => {
console.log(error)
});
},
async updatePassword(req) {
const username = req.user.username;
const user = await Member.findOne({
where: { username: username},
attributes: ['password', 'username']
});
const cmp = await bcrypt.compare(req.body.oldPassword, user.password);
console.log(cmp);
if (cmp) {
const salt = bcrypt.genSaltSync(10);
const hashpassword = bcrypt.hashSync(req.body.newPassword, salt);
return Member
.update(
{
password: hashpassword
},
{
returning: true,
where: {
username: username
}
}
);
}
return "Wrong password"
},
async deactivateAccount(req) {
return Member
.destroy({