aboutsummaryrefslogtreecommitdiff
path: root/controllers/authController.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2017-01-29 22:30:00 -0300
committerPitu <[email protected]>2017-01-29 22:30:00 -0300
commitc64aa8fa2e047a7a11eae4035423910da586638b (patch)
tree922007d0dbf845b95ce0ff54d0069c2451c8d17b /controllers/authController.js
parentUpdated albumsController to use new auth (diff)
downloadhost.fuwn.me-c64aa8fa2e047a7a11eae4035423910da586638b.tar.xz
host.fuwn.me-c64aa8fa2e047a7a11eae4035423910da586638b.zip
Added change password for users
Diffstat (limited to 'controllers/authController.js')
-rw-r--r--controllers/authController.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/controllers/authController.js b/controllers/authController.js
index 86f92fd..464cb7d 100644
--- a/controllers/authController.js
+++ b/controllers/authController.js
@@ -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 \ No newline at end of file