diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-12-14 19:53:31 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-12-14 19:53:31 +0100 |
| commit | 3a42fe7ad797a6f9cf747d2d358015ac992765a7 (patch) | |
| tree | 169c2123067abc677b9e3fa8d19142bd3af3338e /bucky/app/bucky.js | |
| parent | d776e6aa7d1e458ef050c016a4c285aa5887c5f0 (diff) | |
change password - profile stuff
Diffstat (limited to 'bucky/app/bucky.js')
| -rw-r--r-- | bucky/app/bucky.js | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 7dac066..cf74ec2 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -384,6 +384,7 @@ var bucky = module.exports = { } db.getUserByUsername(username).then(function(user){ if (user) { + res.user = user next() } else { @@ -402,43 +403,24 @@ var bucky = module.exports = { updateProfile: function(req, res, next) { var user = res.user "realname location email phone website twitter".split(" ").forEach( (field) => { - res.user.set("field", req.body[field]) + res.user.set(field, req.body[field]) }) next() }, - 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 newPassword = auth.makePassword(res.user, req.body.newpassword) - res.user.set('password', newPassword) - next() - }, uploadAvatar: function(req, res, next) { + if (! req.file) return next() + var dirname = '/bucky/profile/' upload.put({ - file: file, - preserveFilename: true, + file: req.file, + filename: req.user.get('username') + '.jpg', dirname: dirname, unacceptable: function(err){ - reject(err) + res.sendStatus({ error: 'Problem uploading avatar.' }) }, success: function(url){ - var data = { - thread: res.thread.get('id'), - username: req.user.get('username'), - filename: file.originalname, - date: util.now(), - size: file.size, - private: false, - storage: 'i.asdf.us', - } - db.createFile(data).then(function(file){ - resolve(file) - }).catch( (err) => reject(err) ) + console.log(">", url) + res.user.set('avatar', url) + next() } }) }, |
