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.

40 lines
992 B

  1. const _ = require('lodash')
  2. const fs = require('fs-extra')
  3. const path = require('path')
  4. /* global wiki */
  5. module.exports = {
  6. Query: {
  7. authentication(obj, args, context, info) {
  8. switch (args.mode) {
  9. case 'active':
  10. let strategies = _.chain(wiki.auth.strategies).map(str => {
  11. return {
  12. key: str.key,
  13. title: str.title,
  14. useForm: str.useForm
  15. }
  16. }).sortBy(['title']).value()
  17. let localStrategy = _.remove(strategies, str => str.key === 'local')
  18. return _.concat(localStrategy, strategies)
  19. case 'all':
  20. break
  21. default:
  22. return null
  23. }
  24. }
  25. },
  26. Mutation: {},
  27. AuthenticationProvider: {
  28. icon (ap, args) {
  29. return fs.readFileAsync(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${ap.key}.svg`), 'utf8').catch(err => {
  30. if (err.code === 'ENOENT') {
  31. return null
  32. }
  33. throw err
  34. })
  35. }
  36. }
  37. }