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.

38 lines
934 B

  1. 'use strict'
  2. /* global wiki */
  3. // ------------------------------------
  4. // Local Account
  5. // ------------------------------------
  6. const LocalStrategy = require('passport-local').Strategy
  7. module.exports = {
  8. key: 'local',
  9. title: 'Local',
  10. useForm: true,
  11. props: [],
  12. init (passport, conf) {
  13. passport.use('local',
  14. new LocalStrategy({
  15. usernameField: 'email',
  16. passwordField: 'password'
  17. }, (uEmail, uPassword, done) => {
  18. wiki.db.User.findOne({ email: uEmail, provider: 'local' }).then((user) => {
  19. if (user) {
  20. return user.validatePassword(uPassword).then(() => {
  21. return done(null, user) || true
  22. }).catch((err) => {
  23. return done(err, null)
  24. })
  25. } else {
  26. return done(new Error('INVALID_LOGIN'), null)
  27. }
  28. }).catch((err) => {
  29. done(err, null)
  30. })
  31. }
  32. ))
  33. }
  34. }