1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| exports.modifyUser = async (req, res, next) => {
try{
const id = parseInt(req.params.id)
const { username , email, lastname, firstname } = req.body
const password_regex = /^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{8,}$/;
const encryptedPassword = await bcrypt.hash(req.body.password, 10)
const password = req.body.password
connection.query('UPDATE users SET username = ?, email = ?, lastname = ?, firstname = ?, password = ? WHERE id =? ',[username, email, lastname, firstname ,encryptedPassword, id], (error, results) => {
if (error) {
res.status(401).json({err: 'la modification à échouée !' })
}else{
res.status(200).json({"Utilisateur modifié par": `${id}`})
}
})
} catch(err) {
console.error('handle the err: ', err)
}
}; |
Partager