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.

39 lines
1.0 KiB

  1. /* global WIKI */
  2. // ------------------------------------
  3. // Local Account
  4. // ------------------------------------
  5. const LocalStrategy = require('passport-local').Strategy
  6. module.exports = {
  7. init (passport, conf) {
  8. passport.use('local',
  9. new LocalStrategy({
  10. usernameField: 'email',
  11. passwordField: 'password'
  12. }, async (uEmail, uPassword, done) => {
  13. try {
  14. const user = await WIKI.models.users.query().findOne({
  15. email: uEmail,
  16. providerKey: 'local'
  17. })
  18. if (user) {
  19. await user.verifyPassword(uPassword)
  20. if (!user.isActive) {
  21. done(new WIKI.Error.AuthAccountBanned(), null)
  22. } else if (!user.isVerified) {
  23. done(new WIKI.Error.AuthAccountNotVerified(), null)
  24. } else {
  25. done(null, user)
  26. }
  27. } else {
  28. done(new WIKI.Error.AuthLoginFailed(), null)
  29. }
  30. } catch (err) {
  31. done(err, null)
  32. }
  33. })
  34. )
  35. }
  36. }