mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-14 04:14:02 +00:00
Lint server, remove body-parser
This commit is contained in:
@@ -1,37 +1,35 @@
|
||||
const passport = require('passport');
|
||||
const Strategy = require('passport-local');
|
||||
const crypto = require('crypto');
|
||||
const db = require('../db');
|
||||
|
||||
module.exports = function() {
|
||||
const passport = require('passport')
|
||||
const Strategy = require('passport-local')
|
||||
const crypto = require('crypto')
|
||||
const db = require('../db')
|
||||
|
||||
module.exports = function () {
|
||||
// Configure the local strategy for use by Passport.
|
||||
//
|
||||
// The local strategy requires a `verify` function which receives the credentials
|
||||
// (`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) {
|
||||
if (err) { return cb(err); }
|
||||
if (!row) { return cb(null, false, { message: 'Incorrect username or password.' }); }
|
||||
passport.use(new Strategy(function (username, password, cb) {
|
||||
db.get('SELECT rowid AS id, * FROM users WHERE username = ?', [username], function (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) {
|
||||
if (err) { return cb(err); }
|
||||
crypto.pbkdf2(password, row.salt, 10000, 32, 'sha256', function (err, hashedPassword) {
|
||||
if (err) { return cb(err) }
|
||||
if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) {
|
||||
return cb(null, false, { message: 'Incorrect username or password.' });
|
||||
return cb(null, false, { message: 'Incorrect username or password.' })
|
||||
}
|
||||
|
||||
const user = {
|
||||
id: row.id.toString(),
|
||||
username: row.username,
|
||||
displayName: row.name
|
||||
};
|
||||
return cb(null, user);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
}
|
||||
return cb(null, user)
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
// Configure Passport authenticated session persistence.
|
||||
//
|
||||
@@ -40,16 +38,15 @@ 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() {
|
||||
cb(null, { id: user.id, username: user.username });
|
||||
});
|
||||
});
|
||||
passport.serializeUser(function (user, cb) {
|
||||
process.nextTick(function () {
|
||||
cb(null, { id: user.id, username: user.username })
|
||||
})
|
||||
})
|
||||
|
||||
passport.deserializeUser(function(user, cb) {
|
||||
process.nextTick(function() {
|
||||
return cb(null, user);
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
passport.deserializeUser(function (user, cb) {
|
||||
process.nextTick(function () {
|
||||
return cb(null, user)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user