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.

96 lines
3.2 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 Create / Authorize User
  11. p.modal-notify(v-bind:class='{ "is-active": loading }'): i
  12. section
  13. label.label Email address:
  14. p.control.is-fullwidth
  15. input.input(type='text', placeholder='e.g. john.doe@company.com', v-model='email', autofocus)
  16. section
  17. label.label Provider:
  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 Password:
  28. p.control.is-fullwidth
  29. input.input(type='password', placeholder='', v-model='password')
  30. section(v-if='provider=="local"')
  31. label.label Full Name:
  32. p.control.is-fullwidth
  33. input.input(type='text', placeholder='e.g. John Doe', v-model='name')
  34. footer
  35. a.button.is-grey.is-outlined(v-on:click='cancel') Discard
  36. a.button(v-on:click='create', v-if='provider=="local"', v-bind:disabled='loading', v-bind:class='{ "is-disabled": loading, "is-blue": !loading }') Create User
  37. a.button(v-on:click='create', v-if='provider!="local"', v-bind:disabled='loading', v-bind:class='{ "is-disabled": loading, "is-blue": !loading }') Authorize User
  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. loading: false
  49. }
  50. },
  51. computed: {
  52. isShown () {
  53. return this.$store.state.modalCreateUser.shown
  54. }
  55. },
  56. methods: {
  57. cancel () {
  58. this.$store.dispatch('modalCreateUser/close')
  59. this.email = ''
  60. this.provider = 'local'
  61. },
  62. create () {
  63. let self = this
  64. this.loading = true
  65. this.$http.post('/admin/users/create', {
  66. email: this.email,
  67. provider: this.provider,
  68. password: this.password,
  69. name: this.name
  70. }).then(resp => {
  71. return resp.json()
  72. }).then(resp => {
  73. this.loading = false
  74. if (resp.ok) {
  75. this.cancel()
  76. window.location.reload(true)
  77. } else {
  78. self.$store.dispatch('alert', {
  79. style: 'red',
  80. icon: 'square-cross',
  81. msg: resp.msg
  82. })
  83. }
  84. }).catch(err => {
  85. this.loading = false
  86. self.$store.dispatch('alert', {
  87. style: 'red',
  88. icon: 'square-cross',
  89. msg: 'Error: ' + err.body.msg
  90. })
  91. })
  92. }
  93. }
  94. }
  95. </script>