forked from external-repos/noisedash
Use arrow functions
This commit is contained in:
@@ -12,6 +12,7 @@ module.exports = {
|
||||
},
|
||||
rules: {
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
'prefer-arrow-callback': 'error'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ module.exports = function () {
|
||||
// (`username` and `password`) submitted by the user. The function must verify
|
||||
// that the password is correct and then invoke `cb` with a user object, which
|
||||
// will be set at `req.user` in route handlers after authentication.
|
||||
passport.use(new Strategy(function (username, password, cb) {
|
||||
db.get('SELECT rowid AS id, * FROM users WHERE username = ?', [username], function (err, row) {
|
||||
passport.use(new Strategy((username, password, cb) => {
|
||||
db.get('SELECT rowid AS id, * FROM users WHERE username = ?', [username], (err, row) => {
|
||||
if (err) { return cb(err) }
|
||||
if (!row) { return cb(null, false, { message: 'Incorrect username or password.' }) }
|
||||
|
||||
crypto.pbkdf2(password, row.salt, 10000, 32, 'sha256', function (err, hashedPassword) {
|
||||
crypto.pbkdf2(password, row.salt, 10000, 32, 'sha256', (err, hashedPassword) => {
|
||||
if (err) { return cb(err) }
|
||||
if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) {
|
||||
return cb(null, false, { message: 'Incorrect username or password.' })
|
||||
@@ -38,14 +38,14 @@ module.exports = function () {
|
||||
// typical implementation of this is as simple as supplying the user ID when
|
||||
// serializing, and querying the user record by ID from the database when
|
||||
// deserializing.
|
||||
passport.serializeUser(function (user, cb) {
|
||||
process.nextTick(function () {
|
||||
passport.serializeUser((user, cb) => {
|
||||
process.nextTick(() => {
|
||||
cb(null, { id: user.id, username: user.username })
|
||||
})
|
||||
})
|
||||
|
||||
passport.deserializeUser(function (user, cb) {
|
||||
process.nextTick(function () {
|
||||
passport.deserializeUser((user, cb) => {
|
||||
process.nextTick(() => {
|
||||
return cb(null, user)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const db = require('../db')
|
||||
|
||||
module.exports = function () {
|
||||
db.serialize(function () {
|
||||
db.serialize(() => {
|
||||
db.run(`CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
username TEXT UNIQUE,
|
||||
|
||||
@@ -3,11 +3,11 @@ const passport = require('passport')
|
||||
const db = require('../db')
|
||||
const router = express.Router()
|
||||
|
||||
router.post('/login/password', passport.authenticate('local'), function (req, res, next) {
|
||||
router.post('/login/password', passport.authenticate('local'), (req, res, next) => {
|
||||
return res.send('Authenticated and logged in')
|
||||
})
|
||||
|
||||
router.get('/auth', function (req, res) {
|
||||
router.get('/auth', (req, res) => {
|
||||
if (req.user) {
|
||||
res.sendStatus(200)
|
||||
} else {
|
||||
@@ -15,12 +15,12 @@ router.get('/auth', function (req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/admin', function (req, res) {
|
||||
router.get('/admin', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], function (err, row) {
|
||||
db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ router.get('/admin', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/logout', function (req, res) {
|
||||
router.get('/logout', (req, res) => {
|
||||
req.logout()
|
||||
res.sendStatus(200)
|
||||
})
|
||||
|
||||
@@ -2,14 +2,14 @@ const express = require('express')
|
||||
const db = require('../db')
|
||||
const router = express.Router()
|
||||
|
||||
router.post('/profiles', function (req, res) {
|
||||
router.post('/profiles', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
let profileID = 0
|
||||
|
||||
db.serialize(function () {
|
||||
db.serialize(() => {
|
||||
db.run(`INSERT INTO profiles (
|
||||
name,
|
||||
user,
|
||||
@@ -58,7 +58,7 @@ router.post('/profiles', function (req, res) {
|
||||
profileID,
|
||||
s.id
|
||||
],
|
||||
function (err) {
|
||||
(err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -68,14 +68,14 @@ router.post('/profiles', function (req, res) {
|
||||
return res.sendStatus(200)
|
||||
})
|
||||
|
||||
router.get('/profiles', function (req, res) {
|
||||
router.get('/profiles', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
const profiles = []
|
||||
|
||||
db.all('SELECT id, name FROM profiles WHERE user = ?', [req.user.id], function (err, rows) {
|
||||
db.all('SELECT id, name FROM profiles WHERE user = ?', [req.user.id], (err, rows) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -93,7 +93,7 @@ router.get('/profiles', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/profiles/:profileId', function (req, res) {
|
||||
router.get('/profiles/:profileId', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ router.get('/profiles/:profileId', function (req, res) {
|
||||
tremolo_enabled as isTremoloEnabled,
|
||||
tremolo_frequency as tremoloFrequency,
|
||||
tremolo_depth as tremoloDepth
|
||||
FROM profiles WHERE id = ?`, [req.params.profileId], function (err, row) {
|
||||
FROM profiles WHERE id = ?`, [req.params.profileId], (err, row) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -146,13 +146,13 @@ router.get('/profiles/:profileId', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.delete('/profiles/:profileId', function (req, res) {
|
||||
router.delete('/profiles/:profileId', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.serialize(function () {
|
||||
db.get('SELECT user FROM profiles WHERE id = ?', [req.params.profileId], function (err, row) {
|
||||
db.serialize(() => {
|
||||
db.get('SELECT user FROM profiles WHERE id = ?', [req.params.profileId], (err, row) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -162,7 +162,7 @@ router.delete('/profiles/:profileId', function (req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
db.run('DELETE FROM profiles WHERE id = ?', [req.params.profileId], function (err) {
|
||||
db.run('DELETE FROM profiles WHERE id = ?', [req.params.profileId], (err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ const upload = multer({ storage: storage })
|
||||
const db = require('../db')
|
||||
const router = express.Router()
|
||||
|
||||
router.post('/samples', upload.single('sample'), function (req, res, next) {
|
||||
router.post('/samples', upload.single('sample'), (req, res, next) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ router.post('/samples', upload.single('sample'), function (req, res, next) {
|
||||
0,
|
||||
req.user.id
|
||||
],
|
||||
function (err) {
|
||||
(err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
@@ -30,14 +30,14 @@ router.post('/samples', upload.single('sample'), function (req, res, next) {
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/samples', function (req, res) {
|
||||
router.get('/samples', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
const samples = []
|
||||
|
||||
db.all('SELECT id, name, volume FROM samples WHERE user = ?', [req.user.id], function (err, rows) {
|
||||
db.all('SELECT id, name, volume FROM samples WHERE user = ?', [req.user.id], (err, rows) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ const crypto = require('crypto')
|
||||
const db = require('../db')
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/users/current', function (req, res) {
|
||||
router.get('/users/current', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.get('SELECT is_admin as isAdmin, * FROM users WHERE id = ?', [req.user.id], function (err, row) {
|
||||
db.get('SELECT is_admin as isAdmin, * FROM users WHERE id = ?', [req.user.id], (err, row) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -24,14 +24,14 @@ router.get('/users/current', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/users', function (req, res) {
|
||||
router.get('/users', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
const users = []
|
||||
|
||||
db.all('SELECT id, username, name, is_admin as isAdmin FROM users', function (err, rows) {
|
||||
db.all('SELECT id, username, name, is_admin as isAdmin FROM users', (err, rows) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -51,9 +51,9 @@ router.get('/users', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.post('/users', function (req, res) {
|
||||
router.post('/users', (req, res) => {
|
||||
const salt = crypto.randomBytes(16)
|
||||
crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', function (err, hashedPassword) {
|
||||
crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', (err, hashedPassword) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -78,7 +78,7 @@ router.post('/users', function (req, res) {
|
||||
username: req.body.username,
|
||||
displayName: req.body.name
|
||||
}
|
||||
req.login(user, function (err) {
|
||||
req.login(user, (err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
@@ -89,13 +89,13 @@ router.post('/users', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.patch('/users/:userId', function (req, res) {
|
||||
router.patch('/users/:userId', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.serialize(function () {
|
||||
db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], function (err, row) {
|
||||
db.serialize(() => {
|
||||
db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -105,7 +105,7 @@ router.patch('/users/:userId', function (req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
db.run('UPDATE users SET is_admin = ? WHERE id = ?', [req.body.isAdmin ? 1 : 0, req.params.userId], function (err) {
|
||||
db.run('UPDATE users SET is_admin = ? WHERE id = ?', [req.body.isAdmin ? 1 : 0, req.params.userId], (err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
@@ -115,13 +115,13 @@ router.patch('/users/:userId', function (req, res) {
|
||||
})
|
||||
})
|
||||
|
||||
router.delete('/users/:userId', function (req, res) {
|
||||
router.delete('/users/:userId', (req, res) => {
|
||||
if (!req.user) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.serialize(function () {
|
||||
db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], function (err, row) {
|
||||
db.serialize(() => {
|
||||
db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ router.delete('/users/:userId', function (req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
db.run('DELETE FROM users WHERE id = ?', [req.params.userId], function (err) {
|
||||
db.run('DELETE FROM users WHERE id = ?', [req.params.userId], (err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
|
||||
@@ -90,7 +90,7 @@ export default {
|
||||
this.users = response.data.users
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
},
|
||||
@@ -115,7 +115,7 @@ export default {
|
||||
this.getUsers()
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export default {
|
||||
this.$router.push('/login')
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
},
|
||||
|
||||
@@ -69,7 +69,7 @@ export default {
|
||||
this.$router.push('/')
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
this.$router.push('/login')
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ export default {
|
||||
this.profileItems = response.data.profiles
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
},
|
||||
@@ -192,7 +192,7 @@ export default {
|
||||
tremoloDepth: this.tremoloDepth,
|
||||
samples: this.samples
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
|
||||
@@ -221,7 +221,7 @@ export default {
|
||||
this.tremoloDepth = profile.tremoloDepth
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
},
|
||||
@@ -232,7 +232,7 @@ export default {
|
||||
this.populateProfileItems()
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
},
|
||||
@@ -248,7 +248,7 @@ export default {
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
},
|
||||
@@ -268,7 +268,7 @@ export default {
|
||||
this.getSamples()
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
})
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ router.beforeEach((to, from, next) => {
|
||||
next('/login')
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
next('/login')
|
||||
})
|
||||
@@ -63,7 +63,7 @@ router.beforeEach((to, from, next) => {
|
||||
next('/')
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
console.error(error.response)
|
||||
next('/')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user