From 4a4ca06366aaadbb2bd2a6216e1bd2fb00f7af85 Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 30 Jan 2017 04:42:15 -0300 Subject: [PATCH] Forgot it was an array --- controllers/albumsController.js | 12 ++++++------ controllers/authController.js | 6 +++--- controllers/tokenController.js | 3 ++- controllers/uploadController.js | 10 +++++----- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/controllers/albumsController.js b/controllers/albumsController.js index f25f124..79e3ab8 100644 --- a/controllers/albumsController.js +++ b/controllers/albumsController.js @@ -16,7 +16,7 @@ albumsController.list = function(req, res, next){ if(req.params.sidebar === undefined) fields.push('timestamp') - db.table('albums').select(fields).where({enabled: 1, userid: user.id}).then((albums) => { + db.table('albums').select(fields).where({enabled: 1, userid: user[0].id}).then((albums) => { if(req.params.sidebar !== undefined) return res.json({ success: true, albums }) @@ -59,14 +59,14 @@ albumsController.create = function(req, res, next){ db.table('albums').where({ name: name, enabled: 1, - userid: user.id + userid: user[0].id }).then((album) => { if(album.length !== 0) return res.json({ success: false, description: 'There\'s already an album with that name' }) db.table('albums').insert({ name: name, enabled: 1, - userid: user.id, + userid: user[0].id, timestamp: Math.floor(Date.now() / 1000) }).then(() => { return res.json({ success: true }) @@ -88,7 +88,7 @@ albumsController.delete = function(req, res, next){ if(id === undefined || id === '') return res.json({ success: false, description: 'No album specified' }) - db.table('albums').where({id: id, userid: user.id}).update({ enabled: 0 }).then(() => { + db.table('albums').where({id: id, userid: user[0].id}).update({ enabled: 0 }).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'}) }) @@ -109,10 +109,10 @@ albumsController.rename = function(req, res, next){ if(name === undefined || name === '') return res.json({ success: false, description: 'No name specified' }) - db.table('albums').where({name: name, userid: user.id}).then((results) => { + db.table('albums').where({name: name, userid: user[0].id}).then((results) => { if(results.length !== 0) return res.json({ success: false, description: 'Name already in use' }) - db.table('albums').where({id: id, userid: user.id}).update({ name: name }).then(() => { + db.table('albums').where({id: id, userid: user[0].id}).update({ name: name }).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'}) }) diff --git a/controllers/authController.js b/controllers/authController.js index 0d00cea..2773abe 100644 --- a/controllers/authController.js +++ b/controllers/authController.js @@ -30,13 +30,13 @@ authController.register = function(req, res, next){ if(config.enableUserAccounts === false) return res.json({ success: false, description: 'Register is disabled at the moment' }) - let username = req.body.user + let username = req.body.username let password = req.body.password if(username === undefined) return res.json({ success: false, description: 'No username provided' }) if(password === undefined) return res.json({ success: false, description: 'No password provided' }) - if(username.length < 6 || username.length > 32) + if(username.length < 4 || username.length > 32) return res.json({ success: false, description: 'Username must have 6-32 characters' }) if(password.length < 6 || password.length > 64) return res.json({ success: false, description: 'Password must have 6-64 characters' }) @@ -78,7 +78,7 @@ authController.changePassword = function(req, res, next){ 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(() => { + db.table('users').where('id', user[0].id).update({password: hash}).then(() => { return res.json({ success: true}) }).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) }) }) diff --git a/controllers/tokenController.js b/controllers/tokenController.js index 6fc5c98..31b0b3d 100644 --- a/controllers/tokenController.js +++ b/controllers/tokenController.js @@ -1,5 +1,6 @@ const config = require('../config.js') const db = require('knex')(config.database) +const randomstring = require('randomstring') let tokenController = {} @@ -37,7 +38,7 @@ tokenController.change = function(req, res, next){ db.table('users').where('token', token).update({ token: newtoken, timestamp: Math.floor(Date.now() / 1000) - }).then((user) => { + }).then(() => { res.json({ success: true, token: newtoken }) }).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) }) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index d6f8ad5..6b398cc 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -36,7 +36,7 @@ uploadsController.upload = function(req, res, next){ db.table('users').where('token', token).then((user) => { let userid if(user.length > 0) - userid = user.id + userid = user[0].id // Check if user is trying to upload to an album let album = undefined @@ -161,8 +161,8 @@ uploadsController.delete = function(req, res){ db.table('files') .where('id', id) .where(function(){ - if(user.username !== 'root') - this.where('userid', user.id) + if(user[0].username !== 'root') + this.where('userid', user[0].id) }) .then((file) => { @@ -215,8 +215,8 @@ uploadsController.list = function(req, res){ this.where('albumid', req.params.id) }) .where(function(){ - if(user.username !== 'root') - this.where('userid', user.id) + if(user[0].username !== 'root') + this.where('userid', user[0].id) }) .orderBy('id', 'DESC') .limit(25)