mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
934 B
39 lines
934 B
'use strict'
|
|
|
|
/* 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.User.findOne({ email: uEmail, provider: 'local' }).then((user) => {
|
|
if (user) {
|
|
return user.validatePassword(uPassword).then(() => {
|
|
return done(null, user) || true
|
|
}).catch((err) => {
|
|
return done(err, null)
|
|
})
|
|
} else {
|
|
return done(new Error('INVALID_LOGIN'), null)
|
|
}
|
|
}).catch((err) => {
|
|
done(err, null)
|
|
})
|
|
}
|
|
))
|
|
}
|
|
}
|