2020-04-13 00:02:40 +00:00
|
|
|
var passport = require('passport');
|
|
|
|
var LocalStrategy = require('passport-local').Strategy;
|
|
|
|
var mongoose = require('mongoose');
|
|
|
|
var User = mongoose.model('User');
|
|
|
|
|
|
|
|
passport.use(new LocalStrategy({
|
|
|
|
usernameField: 'user[email]',
|
|
|
|
passwordField: 'user[password]'
|
2020-10-20 19:25:00 +00:00
|
|
|
}, function (email, password, done) {
|
|
|
|
User.findOne({ email: email }).then(function (user) {
|
|
|
|
if (!user || !user.validPassword(password)) {
|
|
|
|
return done(null, false, { errors: { 'email or password': 'is invalid' } });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user && user.needsEmailValidation) {
|
|
|
|
return done(null, false, { errors: { 'E-Mail-Bestätigung': 'noch nicht erfolgt' } });
|
2020-04-13 00:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return done(null, user);
|
|
|
|
}).catch(done);
|
|
|
|
}));
|
|
|
|
|