2017-07-29 21:33:08 +00:00
|
|
|
/* global wiki */
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Local Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const LocalStrategy = require('passport-local').Strategy
|
|
|
|
|
2017-09-11 03:00:03 +00:00
|
|
|
module.exports = {
|
|
|
|
key: 'local',
|
|
|
|
title: 'Local',
|
2017-09-25 03:22:33 +00:00
|
|
|
useForm: true,
|
2017-09-11 03:00:03 +00:00
|
|
|
props: [],
|
|
|
|
init (passport, conf) {
|
|
|
|
passport.use('local',
|
|
|
|
new LocalStrategy({
|
|
|
|
usernameField: 'email',
|
|
|
|
passwordField: 'password'
|
|
|
|
}, (uEmail, uPassword, done) => {
|
2018-01-10 01:41:53 +00:00
|
|
|
wiki.db.User.findOne({
|
|
|
|
where: {
|
|
|
|
email: uEmail,
|
|
|
|
provider: 'local'
|
|
|
|
}
|
|
|
|
}).then((user) => {
|
2017-09-11 03:00:03 +00:00
|
|
|
if (user) {
|
|
|
|
return user.validatePassword(uPassword).then(() => {
|
|
|
|
return done(null, user) || true
|
|
|
|
}).catch((err) => {
|
|
|
|
return done(err, null)
|
|
|
|
})
|
|
|
|
} else {
|
2018-01-10 01:41:53 +00:00
|
|
|
return done(new wiki.Error.AuthLoginFailed(), null)
|
2017-09-11 03:00:03 +00:00
|
|
|
}
|
|
|
|
}).catch((err) => {
|
|
|
|
done(err, null)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
))
|
|
|
|
}
|
2017-07-29 21:33:08 +00:00
|
|
|
}
|