wikijs-fork/server/modules/authentication/local.js
2018-05-19 16:40:07 -04:00

40 lines
961 B
JavaScript

/* global WIKI */
// ------------------------------------
// Local Account
// ------------------------------------
const LocalStrategy = require('passport-local').Strategy
module.exports = {
key: 'local',
title: 'Local',
useForm: true,
props: [],
init (passport, conf) {
passport.use('local',
new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
}, (uEmail, uPassword, done) => {
WIKI.db.users.query().findOne({
email: uEmail,
provider: 'local'
}).then((user) => {
if (user) {
return user.verifyPassword(uPassword).then(() => {
return done(null, user) || true
}).catch((err) => {
return done(err, null)
})
} else {
return done(new WIKI.Error.AuthLoginFailed(), null)
}
}).catch((err) => {
done(err, null)
})
}
))
}
}