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.

93 lines
3.0 KiB

  1. <template lang="pug">
  2. .modal(v-bind:class='{ "is-active": isShown }')
  3. .modal-background
  4. .modal-container
  5. .modal-content
  6. header.is-blue
  7. span Create / Authorize User
  8. p.modal-notify(v-bind:class='{ "is-active": loading }'): i
  9. section
  10. label.label Email address:
  11. p.control.is-fullwidth
  12. input.input(type='text', placeholder='e.g. john.doe@company.com', v-model='email', autofocus)
  13. section
  14. label.label Provider:
  15. p.control.is-fullwidth
  16. select(v-model='provider')
  17. option(value='local') Local Database
  18. option(value='windowslive') Microsoft Account
  19. option(value='google') Google ID
  20. option(value='facebook') Facebook
  21. option(value='github') GitHub
  22. option(value='slack') Slack
  23. section(v-if='provider=="local"')
  24. label.label Password:
  25. p.control.is-fullwidth
  26. input.input(type='password', placeholder='', v-model='password')
  27. section(v-if='provider=="local"')
  28. label.label Full Name:
  29. p.control.is-fullwidth
  30. input.input(type='text', placeholder='e.g. John Doe', v-model='name')
  31. footer
  32. a.button.is-grey.is-outlined(v-on:click='cancel') Discard
  33. 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
  34. 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
  35. </template>
  36. <script>
  37. export default {
  38. name: 'admin-users-create',
  39. data () {
  40. return {
  41. email: '',
  42. provider: 'local',
  43. password: '',
  44. name: '',
  45. loading: false
  46. }
  47. },
  48. computed: {
  49. isShown () {
  50. return this.$store.state.adminUsersCreate.shown
  51. }
  52. },
  53. methods: {
  54. cancel () {
  55. this.$store.dispatch('adminUsersCreateClose')
  56. this.email = ''
  57. this.provider = 'local'
  58. },
  59. create () {
  60. let self = this
  61. this.loading = true
  62. this.$http.post('/admin/users/create', {
  63. email: this.email,
  64. provider: this.provider,
  65. password: this.password,
  66. name: this.name
  67. }).then(resp => {
  68. return resp.json()
  69. }).then(resp => {
  70. this.loading = false
  71. if (resp.ok) {
  72. this.cancel()
  73. window.location.reload(true)
  74. } else {
  75. self.$store.dispatch('alert', {
  76. style: 'red',
  77. icon: 'square-cross',
  78. msg: resp.msg
  79. })
  80. }
  81. }).catch(err => {
  82. this.loading = false
  83. self.$store.dispatch('alert', {
  84. style: 'red',
  85. icon: 'square-cross',
  86. msg: 'Error: ' + err.body.msg
  87. })
  88. })
  89. }
  90. }
  91. }
  92. </script>