summaryrefslogtreecommitdiff
path: root/bucky/util/auth.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-14 19:53:31 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-14 19:53:31 +0100
commit3a42fe7ad797a6f9cf747d2d358015ac992765a7 (patch)
tree169c2123067abc677b9e3fa8d19142bd3af3338e /bucky/util/auth.js
parentd776e6aa7d1e458ef050c016a4c285aa5887c5f0 (diff)
change password - profile stuff
Diffstat (limited to 'bucky/util/auth.js')
-rw-r--r--bucky/util/auth.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/bucky/util/auth.js b/bucky/util/auth.js
index 3cc01f0..4556733 100644
--- a/bucky/util/auth.js
+++ b/bucky/util/auth.js
@@ -125,6 +125,20 @@ var auth = module.exports = {
return user.get('password') === auth.makePassword(user.get('username'), pw);
},
+ changePassword: function(req, res, next) {
+ if (! req.body.oldpassword && ! req.body.newpassword) return next()
+ if (req.body.newpassword !== req.body.newpassword2) {
+ return res.send({ error: 'Passwords don\'t match.' })
+ }
+ if (! auth.validPassword(res.user, req.body.oldpassword)) {
+ return res.send({ error: 'Password is incorrect.' })
+ }
+ var username = req.user.get('username')
+ var newPassword = auth.makePassword(username, req.body.newpassword)
+ res.user.set('password', newPassword)
+ next()
+ },
+
verifyLocalUser: function (username, password, done) {
// handle passwords!!
db.getUserByUsername(username).then(function(user){
@@ -143,7 +157,7 @@ var auth = module.exports = {
checkin: function (req, res) {
var user = util.sanitizeUser(req.user)
- res.json(user)
+ res.json({ user: user })
},
logout: function (req, res) {