login.vue 2.2 KB

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