Forgot it was an array

This commit is contained in:
Pitu 2017-01-30 04:42:15 -03:00
parent 1d45d6d881
commit 4a4ca06366
4 changed files with 16 additions and 15 deletions

View File

@ -16,7 +16,7 @@ albumsController.list = function(req, res, next){
if(req.params.sidebar === undefined) if(req.params.sidebar === undefined)
fields.push('timestamp') 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) if(req.params.sidebar !== undefined)
return res.json({ success: true, albums }) return res.json({ success: true, albums })
@ -59,14 +59,14 @@ albumsController.create = function(req, res, next){
db.table('albums').where({ db.table('albums').where({
name: name, name: name,
enabled: 1, enabled: 1,
userid: user.id userid: user[0].id
}).then((album) => { }).then((album) => {
if(album.length !== 0) return res.json({ success: false, description: 'There\'s already an album with that name' }) if(album.length !== 0) return res.json({ success: false, description: 'There\'s already an album with that name' })
db.table('albums').insert({ db.table('albums').insert({
name: name, name: name,
enabled: 1, enabled: 1,
userid: user.id, userid: user[0].id,
timestamp: Math.floor(Date.now() / 1000) timestamp: Math.floor(Date.now() / 1000)
}).then(() => { }).then(() => {
return res.json({ success: true }) return res.json({ success: true })
@ -88,7 +88,7 @@ albumsController.delete = function(req, res, next){
if(id === undefined || id === '') if(id === undefined || id === '')
return res.json({ success: false, description: 'No album specified' }) 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 }) 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'}) })
}).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 === '') if(name === undefined || name === '')
return res.json({ success: false, description: 'No name specified' }) 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' }) 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 }) 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'}) })
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) }) }).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })

View File

@ -30,13 +30,13 @@ authController.register = function(req, res, next){
if(config.enableUserAccounts === false) if(config.enableUserAccounts === false)
return res.json({ success: false, description: 'Register is disabled at the moment' }) 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 let password = req.body.password
if(username === undefined) return res.json({ success: false, description: 'No username provided' }) 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(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' }) return res.json({ success: false, description: 'Username must have 6-32 characters' })
if(password.length < 6 || password.length > 64) if(password.length < 6 || password.length > 64)
return res.json({ success: false, description: 'Password must have 6-64 characters' }) 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) { bcrypt.hash(password, saltRounds, function(err, hash) {
if(err) return res.json({ success: false, description: 'Error generating password 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}) 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'}) })
}) })

View File

@ -1,5 +1,6 @@
const config = require('../config.js') const config = require('../config.js')
const db = require('knex')(config.database) const db = require('knex')(config.database)
const randomstring = require('randomstring')
let tokenController = {} let tokenController = {}
@ -37,7 +38,7 @@ tokenController.change = function(req, res, next){
db.table('users').where('token', token).update({ db.table('users').where('token', token).update({
token: newtoken, token: newtoken,
timestamp: Math.floor(Date.now() / 1000) timestamp: Math.floor(Date.now() / 1000)
}).then((user) => { }).then(() => {
res.json({ success: true, token: newtoken }) res.json({ success: true, token: newtoken })
}).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) }) }).catch(function(error) { console.log(error); res.json({success: false, description: 'error'}) })

View File

@ -36,7 +36,7 @@ uploadsController.upload = function(req, res, next){
db.table('users').where('token', token).then((user) => { db.table('users').where('token', token).then((user) => {
let userid let userid
if(user.length > 0) if(user.length > 0)
userid = user.id userid = user[0].id
// Check if user is trying to upload to an album // Check if user is trying to upload to an album
let album = undefined let album = undefined
@ -161,8 +161,8 @@ uploadsController.delete = function(req, res){
db.table('files') db.table('files')
.where('id', id) .where('id', id)
.where(function(){ .where(function(){
if(user.username !== 'root') if(user[0].username !== 'root')
this.where('userid', user.id) this.where('userid', user[0].id)
}) })
.then((file) => { .then((file) => {
@ -215,8 +215,8 @@ uploadsController.list = function(req, res){
this.where('albumid', req.params.id) this.where('albumid', req.params.id)
}) })
.where(function(){ .where(function(){
if(user.username !== 'root') if(user[0].username !== 'root')
this.where('userid', user.id) this.where('userid', user[0].id)
}) })
.orderBy('id', 'DESC') .orderBy('id', 'DESC')
.limit(25) .limit(25)