update user
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user