login.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template lang="pug">
  2. .login(:class='{ "is-error": error }')
  3. .login-container(:class='{ "is-expanded": strategies.length > 1 }')
  4. .login-error(v-if='error')
  5. strong
  6. i.icon-warning-outline
  7. | {{ error.title }}
  8. span {{ error.message }}
  9. .login-providers(v-show='strategies.length > 1')
  10. button(v-for='strategy in strategies', :class='{ "is-active": strategy.key === selectedStrategy }', @click='selectStrategy(strategy.key, strategy.useForm)', :title='strategy.title')
  11. em(v-html='strategy.icon')
  12. span {{ strategy.title }}
  13. .login-frame
  14. h1 {{ siteTitle }}
  15. h2 {{ $t('auth:loginrequired') }}
  16. form(method='post', action='/login')
  17. input#login-user(type='text', name='email', :placeholder='$t("auth:fields.emailuser")')
  18. input#login-pass(type='password', name='password', :placeholder='$t("auth:fields.password")')
  19. button.button.is-light-blue.is-fullwidth(type='submit')
  20. span {{ $t('auth:actions.login') }}
  21. .login-copyright
  22. span {{ $t('footer.poweredby') }}
  23. a(href='https://wiki.js.org', rel='external', title='Wiki.js') Wiki.js
  24. </template>
  25. <script>
  26. /* global CONSTANTS, graphQL, siteConfig */
  27. export default {
  28. name: 'login',
  29. data() {
  30. return {
  31. error: false,
  32. strategies: [],
  33. selectedStrategy: 'local'
  34. }
  35. },
  36. computed: {
  37. siteTitle() {
  38. return siteConfig.title
  39. }
  40. },
  41. methods: {
  42. selectStrategy(key, useForm) {
  43. this.selectedStrategy = key
  44. if (!useForm) {
  45. window.location.assign(siteConfig.path + '/login/' + key)
  46. }
  47. },
  48. refreshStrategies() {
  49. graphQL.query({
  50. query: CONSTANTS.GRAPHQL.GQL_QUERY_AUTHENTICATION,
  51. variables: {
  52. mode: 'active'
  53. }
  54. }).then(resp => {
  55. if (resp.data.authentication) {
  56. this.strategies = resp.data.authentication
  57. } else {
  58. throw new Error('No authentication providers available!')
  59. }
  60. }).catch(err => {
  61. console.error(err)
  62. })
  63. }
  64. },
  65. mounted() {
  66. this.refreshStrategies()
  67. }
  68. }
  69. </script>