admin-users-create.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template lang="pug">
  2. v-dialog(v-model='isShown', max-width='650', persistent)
  3. v-card.wiki-form
  4. .dialog-header.is-short
  5. span New User
  6. v-card-text
  7. v-select(
  8. :items='providers'
  9. item-text='title'
  10. item-value='key'
  11. outline
  12. prepend-icon='business'
  13. v-model='provider'
  14. label='Provider'
  15. )
  16. v-text-field(
  17. outline
  18. prepend-icon='email'
  19. v-model='email'
  20. label='Email Address'
  21. ref='emailInput'
  22. )
  23. v-text-field(
  24. v-if='provider === `local`'
  25. outline
  26. prepend-icon='lock'
  27. append-icon='casino'
  28. v-model='password'
  29. :label='mustChangePwd ? `Temporary Password` : `Password`'
  30. counter='255'
  31. @click:append='generatePwd'
  32. )
  33. v-text-field(
  34. outline
  35. prepend-icon='person'
  36. v-model='name'
  37. label='Name'
  38. )
  39. v-select(
  40. :items='groups'
  41. item-text='name'
  42. item-value='key'
  43. outline
  44. prepend-icon='people'
  45. v-model='group'
  46. label='Assign to Group(s)...'
  47. clearable
  48. multiple
  49. )
  50. v-divider
  51. v-checkbox(
  52. color='primary'
  53. label='Require password change on first login'
  54. v-if='provider === `local`'
  55. v-model='mustChangePwd'
  56. hide-details
  57. )
  58. v-checkbox(
  59. color='primary'
  60. label='Send a welcome email'
  61. hide-details
  62. v-model='sendWelcomeEmail'
  63. )
  64. v-card-chin
  65. v-spacer
  66. v-btn(flat, @click='isShown = false') Cancel
  67. v-btn(color='primary', @click='newUser(true)') Create
  68. v-btn(color='primary', @click='newUser(false)') Create and Close
  69. </template>
  70. <script>
  71. import uuidv4 from 'uuid/v4'
  72. import providersQuery from 'gql/admin/users/users-query-strategies.gql'
  73. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  74. export default {
  75. props: {
  76. value: {
  77. type: Boolean,
  78. default: false
  79. }
  80. },
  81. data() {
  82. return {
  83. providers: [],
  84. provider: 'local',
  85. email: '',
  86. password: '',
  87. name: '',
  88. groups: [],
  89. group: '',
  90. mustChangePwd: false,
  91. sendWelcomeEmail: false
  92. }
  93. },
  94. computed: {
  95. isShown: {
  96. get() { return this.value },
  97. set(val) { this.$emit('input', val) }
  98. }
  99. },
  100. watch: {
  101. value(newValue, oldValue) {
  102. if (newValue) {
  103. this.$nextTick(() => {
  104. this.$refs.emailInput.focus()
  105. })
  106. }
  107. }
  108. },
  109. methods: {
  110. async newUser() {
  111. this.isShown = false
  112. },
  113. generatePwd() {
  114. this.password = uuidv4().slice(-12)
  115. }
  116. },
  117. apollo: {
  118. providers: {
  119. query: providersQuery,
  120. fetchPolicy: 'network-only',
  121. update: (data) => data.authentication.strategies,
  122. watchLoading (isLoading) {
  123. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-strategies-refresh')
  124. }
  125. },
  126. groups: {
  127. query: groupsQuery,
  128. fetchPolicy: 'network-only',
  129. update: (data) => data.groups.list,
  130. watchLoading (isLoading) {
  131. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  132. }
  133. }
  134. }
  135. }
  136. </script>