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.
42 lines
989 B
42 lines
989 B
8 years ago
|
/* global wiki */
|
||
|
|
||
|
// ------------------------------------
|
||
|
// Local Account
|
||
|
// ------------------------------------
|
||
|
|
||
|
const LocalStrategy = require('passport-local').Strategy
|
||
|
|
||
7 years ago
|
module.exports = {
|
||
|
key: 'local',
|
||
|
title: 'Local',
|
||
7 years ago
|
useForm: true,
|
||
7 years ago
|
props: [],
|
||
|
init (passport, conf) {
|
||
|
passport.use('local',
|
||
|
new LocalStrategy({
|
||
|
usernameField: 'email',
|
||
|
passwordField: 'password'
|
||
|
}, (uEmail, uPassword, done) => {
|
||
7 years ago
|
wiki.db.User.findOne({
|
||
|
where: {
|
||
|
email: uEmail,
|
||
|
provider: 'local'
|
||
|
}
|
||
|
}).then((user) => {
|
||
7 years ago
|
if (user) {
|
||
|
return user.validatePassword(uPassword).then(() => {
|
||
|
return done(null, user) || true
|
||
|
}).catch((err) => {
|
||
|
return done(err, null)
|
||
|
})
|
||
|
} else {
|
||
7 years ago
|
return done(new wiki.Error.AuthLoginFailed(), null)
|
||
7 years ago
|
}
|
||
|
}).catch((err) => {
|
||
|
done(err, null)
|
||
|
})
|
||
|
}
|
||
|
))
|
||
|
}
|
||
8 years ago
|
}
|