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.

37 lines
917 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. props: [],
  11. init (passport, conf) {
  12. passport.use('local',
  13. new LocalStrategy({
  14. usernameField: 'email',
  15. passwordField: 'password'
  16. }, (uEmail, uPassword, done) => {
  17. wiki.db.User.findOne({ email: uEmail, provider: 'local' }).then((user) => {
  18. if (user) {
  19. return user.validatePassword(uPassword).then(() => {
  20. return done(null, user) || true
  21. }).catch((err) => {
  22. return done(err, null)
  23. })
  24. } else {
  25. return done(new Error('INVALID_LOGIN'), null)
  26. }
  27. }).catch((err) => {
  28. done(err, null)
  29. })
  30. }
  31. ))
  32. }
  33. }