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)
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'}) })

View File

@ -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'}) })
})

View File

@ -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'}) })

View File

@ -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)