mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-21 12:49:07 +00:00
Added change password for users
This commit is contained in:
parent
751a876360
commit
c64aa8fa2e
@ -61,4 +61,28 @@ authController.register = function(req, res, next){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authController.changePassword = function(req, res, next){
|
||||||
|
|
||||||
|
let token = req.headers.token
|
||||||
|
if(token === undefined) return res.status(401).json({ success: false, description: 'No token provided' })
|
||||||
|
|
||||||
|
db.table('users').where('token', token).then((user) => {
|
||||||
|
if(user.length === 0) return res.status(401).json({ success: false, description: 'Invalid token'})
|
||||||
|
|
||||||
|
let password = req.body.password
|
||||||
|
if(password === undefined) return res.json({ success: false, description: 'No password provided' })
|
||||||
|
if(password.length < 6 || password.length > 64)
|
||||||
|
return res.json({ success: false, description: 'Password must have 6-64 characters' })
|
||||||
|
|
||||||
|
bcrypt.hash(password, saltRounds, function(err, hash) {
|
||||||
|
if(err) return res.json({ success: false, description: 'Error generating password hash (╯°□°)╯︵ ┻━┻' })
|
||||||
|
|
||||||
|
db.table('users').where('id', user.id).update({password: hash}).then(() => {
|
||||||
|
return res.json({ success: true})
|
||||||
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
||||||
|
})
|
||||||
|
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = authController
|
module.exports = authController
|
Loading…
Reference in New Issue
Block a user