admin-mail.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/svg/icon-new-post.svg', alt='Mail', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{ $t('admin:mail.title') }}
  9. .subheading.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:mail.subtitle') }}
  10. v-spacer
  11. v-btn.animated.fadeInDown(color='success', depressed, @click='save', large)
  12. v-icon(left) check
  13. span {{$t('common:actions.apply')}}
  14. v-form.pt-3
  15. v-layout(row wrap)
  16. v-flex(lg6 xs12)
  17. v-form
  18. v-card.wiki-form.animated.fadeInUp
  19. v-toolbar(color='primary', dark, dense, flat)
  20. v-toolbar-title
  21. .subheading {{ $t('admin:mail.configuration') }}
  22. v-subheader {{ $t('admin:mail.sender') }}
  23. .px-3.pb-3
  24. v-text-field(
  25. outline
  26. v-model='config.senderName'
  27. :label='$t(`admin:mail.senderName`)'
  28. required
  29. :counter='255'
  30. prepend-icon='person'
  31. )
  32. v-text-field(
  33. outline
  34. v-model='config.senderEmail'
  35. :label='$t(`admin:mail.senderEmail`)'
  36. required
  37. :counter='255'
  38. prepend-icon='email'
  39. )
  40. v-divider
  41. v-subheader {{ $t('admin:mail.smtp') }}
  42. .px-3.pb-3
  43. v-text-field(
  44. outline
  45. v-model='config.host'
  46. :label='$t(`admin:mail.smtpHost`)'
  47. required
  48. :counter='255'
  49. prepend-icon='memory'
  50. )
  51. v-text-field(
  52. outline
  53. v-model='config.port'
  54. :label='$t(`admin:mail.smtpPort`)'
  55. required
  56. prepend-icon='router'
  57. persistent-hint
  58. :hint='$t(`admin:mail.smtpPortHint`)'
  59. style='max-width: 300px;'
  60. )
  61. v-switch(
  62. v-model='config.secure'
  63. :label='$t(`admin:mail.smtpTLS`)'
  64. color='primary'
  65. persistent-hint
  66. :hint='$t(`admin:mail.smtpTLSHint`)'
  67. prepend-icon='vpn_lock'
  68. )
  69. v-text-field.mt-3(
  70. outline
  71. v-model='config.user'
  72. :label='$t(`admin:mail.smtpUser`)'
  73. required
  74. :counter='255'
  75. prepend-icon='lock_outline'
  76. )
  77. v-text-field(
  78. outline
  79. v-model='config.pass'
  80. :label='$t(`admin:mail.smtpPwd`)'
  81. required
  82. prepend-icon='lock'
  83. type='password'
  84. )
  85. v-flex(lg6 xs12)
  86. v-card.wiki-form.animated.fadeInUp.wait-p2s
  87. v-form
  88. v-toolbar(color='primary', dark, dense, flat)
  89. v-toolbar-title
  90. .subheading {{ $t('admin:mail.dkim') }}
  91. .pa-3
  92. .body-2.grey--text.text--darken-2 {{ $t('admin:mail.dkimHint') }}
  93. v-switch(
  94. v-model='config.useDKIM'
  95. :label='$t(`admin:mail.dkimUse`)'
  96. color='primary'
  97. prepend-icon='vpn_key'
  98. )
  99. v-text-field(
  100. outline
  101. v-model='config.dkimDomainName'
  102. :label='$t(`admin:mail.dkimDomainName`)'
  103. :counter='255'
  104. prepend-icon='vpn_key'
  105. :disabled='!config.useDKIM'
  106. )
  107. v-text-field(
  108. outline
  109. v-model='config.dkimKeySelector'
  110. :label='$t(`admin:mail.dkimKeySelector`)'
  111. :counter='255'
  112. prepend-icon='vpn_key'
  113. :disabled='!config.useDKIM'
  114. )
  115. v-text-field(
  116. outline
  117. v-model='config.dkimPrivateKey'
  118. :label='$t(`admin:mail.dkimPrivateKey`)'
  119. prepend-icon='vpn_key'
  120. persistent-hint
  121. :hint='$t(`admin:mail.dkimPrivateKeyHint`)'
  122. :disabled='!config.useDKIM'
  123. )
  124. v-card.mt-3.wiki-form.animated.fadeInUp.wait-p3s
  125. v-form
  126. v-toolbar(color='teal', dark, dense, flat)
  127. v-toolbar-title
  128. .subheading {{ $t('admin:mail.test') }}
  129. .pa-3
  130. .body-2.grey--text.text--darken-2 {{ $t('admin:mail.testHint') }}
  131. v-text-field.mt-3(
  132. outline
  133. v-model='testEmail'
  134. :label='$t(`admin:mail.testRecipient`)'
  135. :counter='255'
  136. prepend-icon='mail'
  137. disabled
  138. )
  139. v-card-chin
  140. v-spacer
  141. v-btn(color='teal', :dark='false', disabled) {{ $t('admin:mail.testSend') }}
  142. </template>
  143. <script>
  144. import _ from 'lodash'
  145. import { get } from 'vuex-pathify'
  146. import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql'
  147. import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql'
  148. export default {
  149. data() {
  150. return {
  151. config: {
  152. senderName: '',
  153. senderEmail: '',
  154. host: '',
  155. port: 0,
  156. secure: false,
  157. user: '',
  158. pass: '',
  159. useDKIM: false,
  160. dkimDomainName: '',
  161. dkimKeySelector: '',
  162. dkimPrivateKey: ''
  163. },
  164. testEmail: ''
  165. }
  166. },
  167. computed: {
  168. darkMode: get('site/dark')
  169. },
  170. methods: {
  171. async save () {
  172. try {
  173. await this.$apollo.mutate({
  174. mutation: mailUpdateConfigMutation,
  175. variables: {
  176. senderName: this.config.senderName || '',
  177. senderEmail: this.config.senderEmail || '',
  178. host: this.config.host || '',
  179. port: _.toSafeInteger(this.config.port) || 0,
  180. secure: this.config.secure || false,
  181. user: this.config.user || '',
  182. pass: this.config.pass || '',
  183. useDKIM: this.config.useDKIM || false,
  184. dkimDomainName: this.config.dkimDomainName || '',
  185. dkimKeySelector: this.config.dkimKeySelector || '',
  186. dkimPrivateKey: this.config.dkimPrivateKey || ''
  187. },
  188. watchLoading (isLoading) {
  189. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-update')
  190. }
  191. })
  192. this.$store.commit('showNotification', {
  193. style: 'success',
  194. message: this.$t('admin:mail.saveSuccess'),
  195. icon: 'check'
  196. })
  197. } catch (err) {
  198. this.$store.commit('pushGraphError', err)
  199. }
  200. }
  201. },
  202. apollo: {
  203. config: {
  204. query: mailConfigQuery,
  205. fetchPolicy: 'network-only',
  206. update: (data) => _.cloneDeep(data.mail.config),
  207. watchLoading (isLoading) {
  208. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-refresh')
  209. }
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang='scss'>
  215. </style>