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.

105 lines
3.5 KiB

  1. <template lang="pug">
  2. transition(:duration="400")
  3. .modal(v-show='isShown', v-cloak)
  4. transition(name='modal-background')
  5. .modal-background(v-show='isShown')
  6. .modal-container
  7. transition(name='modal-content')
  8. .modal-content(v-show='isShown')
  9. header.is-blue
  10. span {{ $t('modal.createusertitle') }}
  11. p.modal-notify(:class='{ "is-active": isLoading }'): i
  12. section
  13. label.label {{ $t('modal.createuseremail') }}
  14. p.control.is-fullwidth
  15. input.input(type='text', :placeholder='$t("modal.createuseremailplaceholder")', v-model='email', ref='createUserEmailInput')
  16. section
  17. label.label {{ $t('modal.createuserprovider') }}
  18. p.control.is-fullwidth
  19. select(v-model='provider')
  20. option(value='local') Local Database
  21. option(value='windowslive') Microsoft Account
  22. option(value='google') Google ID
  23. option(value='facebook') Facebook
  24. option(value='github') GitHub
  25. option(value='slack') Slack
  26. section(v-if='provider=="local"')
  27. label.label {{ $t('modal.createuserpassword') }}
  28. p.control.is-fullwidth
  29. input.input(type='password', placeholder='', v-model='password')
  30. section(v-if='provider=="local"')
  31. label.label {{ $t('modal.createusername') }}
  32. p.control.is-fullwidth
  33. input.input(type='text', :placeholder='$t("modal.createusernameplaceholder")', v-model='name')
  34. footer
  35. a.button.is-grey.is-outlined(@click='cancel') {{ $t('modal.discard') }}
  36. a.button(@click='create', v-if='provider=="local"', :disabled='isLoading', :class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuser') }}
  37. a.button(@click='create', v-if='provider!="local"', :disabled='isLoading', :class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuserauthorize') }}
  38. </template>
  39. <script>
  40. export default {
  41. name: 'modal-create-user',
  42. data() {
  43. return {
  44. email: '',
  45. provider: 'local',
  46. password: '',
  47. name: '',
  48. isLoading: false
  49. }
  50. },
  51. computed: {
  52. isShown() {
  53. return this.$store.state.modalCreateUser.shown
  54. }
  55. },
  56. methods: {
  57. init() {
  58. let self = this
  59. self._.delay(() => {
  60. self.$refs.createUserEmailInput.focus()
  61. }, 100)
  62. },
  63. cancel() {
  64. this.$store.dispatch('modalCreateUser/close')
  65. this.email = ''
  66. this.provider = 'local'
  67. },
  68. create() {
  69. let self = this
  70. this.isLoading = true
  71. this.$http.post('/admin/users/create', {
  72. email: this.email,
  73. provider: this.provider,
  74. password: this.password,
  75. name: this.name
  76. }).then(resp => {
  77. return resp.json()
  78. }).then(resp => {
  79. this.isLoading = false
  80. if (resp.ok) {
  81. this.cancel()
  82. window.location.reload(true)
  83. } else {
  84. self.$store.dispatch('alert', {
  85. style: 'red',
  86. icon: 'square-cross',
  87. msg: resp.msg
  88. })
  89. }
  90. }).catch(err => {
  91. this.isLoading = false
  92. self.$store.dispatch('alert', {
  93. style: 'red',
  94. icon: 'square-cross',
  95. msg: 'Error: ' + err.body.msg
  96. })
  97. })
  98. }
  99. },
  100. mounted() {
  101. this.$root.$on('modalCreateUser/init', this.init)
  102. }
  103. }
  104. </script>