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

36 lines
868 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 = {
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
}