2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2017-07-29 21:33:08 +00:00
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Local Account
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
|
|
const LocalStrategy = require('passport-local').Strategy
|
|
|
|
|
2017-09-11 03:00:03 +00:00
|
|
|
module.exports = {
|
|
|
|
init (passport, conf) {
|
|
|
|
passport.use('local',
|
|
|
|
new LocalStrategy({
|
|
|
|
usernameField: 'email',
|
|
|
|
passwordField: 'password'
|
|
|
|
}, (uEmail, uPassword, done) => {
|
2018-05-19 20:40:07 +00:00
|
|
|
WIKI.db.users.query().findOne({
|
|
|
|
email: uEmail,
|
2018-07-22 04:29:39 +00:00
|
|
|
providerKey: 'local'
|
2018-01-10 01:41:53 +00:00
|
|
|
}).then((user) => {
|
2017-09-11 03:00:03 +00:00
|
|
|
if (user) {
|
2018-05-19 20:40:07 +00:00
|
|
|
return user.verifyPassword(uPassword).then(() => {
|
2018-05-20 22:50:51 +00:00
|
|
|
done(null, user)
|
2017-09-11 03:00:03 +00:00
|
|
|
}).catch((err) => {
|
2018-05-20 22:50:51 +00:00
|
|
|
done(err, null)
|
2017-09-11 03:00:03 +00:00
|
|
|
})
|
|
|
|
} else {
|
2018-05-20 22:50:51 +00:00
|
|
|
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
|
|
|
}
|