summaryrefslogtreecommitdiff
path: root/bucky/app/bucky.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-14 08:03:07 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-14 08:03:07 +0100
commitd776e6aa7d1e458ef050c016a4c285aa5887c5f0 (patch)
tree687c4b7a4a8a123c04186e482f3680659a121a40 /bucky/app/bucky.js
parentf9a0743696c5e21d81ae0e215e36358788e708df (diff)
edit profile backend stuff
Diffstat (limited to 'bucky/app/bucky.js')
-rw-r--r--bucky/app/bucky.js52
1 files changed, 49 insertions, 3 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index f3ea689..7dac066 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -384,7 +384,6 @@ var bucky = module.exports = {
}
db.getUserByUsername(username).then(function(user){
if (user) {
- res.user = util.sanitizeUser(user)
next()
}
else {
@@ -392,12 +391,59 @@ var bucky = module.exports = {
}
})
},
+ sanitizeUser: function(req, res, next) {
+ res.user = util.sanitizeUser(res.user)
+ next()
+ },
bumpLastSeen: function(req, res, next) {
req.user.set('lastseen', util.now())
req.user.save().then( () => next() )
},
- updateUser: function(req, res, next) {
-
+ 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])
+ })
+ 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) {
+ upload.put({
+ file: file,
+ preserveFilename: true,
+ dirname: dirname,
+ unacceptable: function(err){
+ reject(err)
+ },
+ 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) )
+ }
+ })
+ },
+ saveUser: function(req, res, next){
+ res.user.save().then( () => next() )
},
/* PRIVACY */