login.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. export default {
  27. name: 'login',
  28. data() {
  29. return {
  30. error: false,
  31. strategies: [],
  32. selectedStrategy: 'local'
  33. }
  34. },
  35. computed: {
  36. siteTitle() {
  37. return siteConfig.title
  38. }
  39. },
  40. methods: {
  41. selectStrategy(key, useForm) {
  42. this.selectedStrategy = key
  43. if (!useForm) {
  44. window.location.assign(siteConfig.path + '/login/' + key)
  45. }
  46. },
  47. refreshStrategies() {
  48. graphQL.query({
  49. query: CONSTANTS.GRAPHQL.GQL_QUERY_AUTHENTICATION,
  50. variables: {
  51. mode: 'active'
  52. }
  53. }).then(resp => {
  54. if (resp.data.authentication) {
  55. this.strategies = resp.data.authentication
  56. } else {
  57. throw new Error('No authentication providers available!')
  58. }
  59. }).catch(err => {
  60. console.error(err)
  61. })
  62. }
  63. },
  64. mounted() {
  65. this.refreshStrategies()
  66. }
  67. }
  68. </script>