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.

41 lines
989 B

  1. /* global WIKI */
  2. // ------------------------------------
  3. // Local Account
  4. // ------------------------------------
  5. const LocalStrategy = require('passport-local').Strategy
  6. module.exports = {
  7. key: 'local',
  8. title: 'Local',
  9. useForm: true,
  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({
  18. where: {
  19. email: uEmail,
  20. provider: 'local'
  21. }
  22. }).then((user) => {
  23. if (user) {
  24. return user.validatePassword(uPassword).then(() => {
  25. return done(null, user) || true
  26. }).catch((err) => {
  27. return done(err, null)
  28. })
  29. } else {
  30. return done(new WIKI.Error.AuthLoginFailed(), null)
  31. }
  32. }).catch((err) => {
  33. done(err, null)
  34. })
  35. }
  36. ))
  37. }
  38. }