add passport local strategy, jwt and express jwt

This commit is contained in:
Shannon Sterz 2016-02-23 17:45:22 +01:00
parent 12e529b053
commit ad14a07114
2 changed files with 25 additions and 0 deletions

21
nodejs/config/passport.js Normal file
View file

@ -0,0 +1,21 @@
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var models = new require('../models');
var users = new models.Users();
passport.use(new LocalStrategy(
function(username, password, done) {
users.findByName(username, function (err, results, fields) {
if (err) { return done(err); }
if (results.length != 1) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!users.validPassword(password, results[0])) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, results[0]);
});
}
));

View file

@ -11,8 +11,12 @@
"debug": "~2.2.0", "debug": "~2.2.0",
"ejs": "~2.3.3", "ejs": "~2.3.3",
"express": "~4.13.1", "express": "~4.13.1",
"express-jwt": "^3.3.0",
"jsonwebtoken": "^5.7.0",
"morgan": "~1.6.1", "morgan": "~1.6.1",
"mysql": "^2.10.2", "mysql": "^2.10.2",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"serialport": "^2.0.6", "serialport": "^2.0.6",
"serve-favicon": "~2.3.0" "serve-favicon": "~2.3.0"
} }