wikijs-fork/server/modules/authentication/local.js

40 lines
932 B
JavaScript
Raw Normal View History

/* global WIKI */
2017-07-29 21:33:08 +00:00
// ------------------------------------
// 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'
2018-01-10 01:41:53 +00:00
}).then((user) => {
if (user) {
return user.verifyPassword(uPassword).then(() => {
2018-05-20 22:50:51 +00:00
done(null, user)
}).catch((err) => {
2018-05-20 22:50:51 +00:00
done(err, null)
})
} else {
2018-05-20 22:50:51 +00:00
done(new WIKI.Error.AuthLoginFailed(), null)
}
}).catch((err) => {
done(err, null)
})
}
))
}
2017-07-29 21:33:08 +00:00
}