refactor: project cleanup + onboarding page
This commit is contained in:
41
server/modules/authentication/local.js
Normal file
41
server/modules/authentication/local.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/* 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({
|
||||
where: {
|
||||
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 wiki.Error.AuthLoginFailed(), null)
|
||||
}
|
||||
}).catch((err) => {
|
||||
done(err, null)
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user