admin-mail.vue 9.36 KB
Newer Older
1 2
<template lang='pug'>
  v-container(fluid, grid-list-lg)
Nick's avatar
Nick committed
3
    v-layout(row, wrap)
4 5
      v-flex(xs12)
        .admin-header
6
          img.animated.fadeInUp(src='/_assets/svg/icon-new-post.svg', alt='Mail', style='width: 80px;')
7
          .admin-header-title
Nick's avatar
Nick committed
8
            .headline.primary--text.animated.fadeInLeft {{ $t('admin:mail.title') }}
9
            .subtitle-1.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:mail.subtitle') }}
10
          v-spacer
Nick's avatar
Nick committed
11
          v-btn.animated.fadeInDown(color='success', depressed, @click='save', large)
12
            v-icon(left) mdi-check
13 14 15 16 17
            span {{$t('common:actions.apply')}}
        v-form.pt-3
          v-layout(row wrap)
            v-flex(lg6 xs12)
              v-form
18
                v-card.animated.fadeInUp
19
                  v-toolbar(color='primary', dark, dense, flat)
20 21 22
                    v-toolbar-title.subtitle-1 {{ $t('admin:mail.configuration') }}
                  .overline.pa-4.grey--text {{ $t('admin:mail.sender') }}
                  .px-4
23
                    v-text-field(
24
                      outlined
25
                      v-model='config.senderName'
26
                      :label='$t(`admin:mail.senderName`)'
27 28
                      required
                      :counter='255'
29
                      prepend-icon='mdi-mailbox'
30 31
                      )
                    v-text-field(
32
                      outlined
33
                      v-model='config.senderEmail'
34
                      :label='$t(`admin:mail.senderEmail`)'
35 36
                      required
                      :counter='255'
37
                      prepend-icon='mdi-mailbox'
38 39
                      )
                  v-divider
40 41
                  .overline.pa-4.grey--text {{ $t('admin:mail.smtp') }}
                  .px-4
42
                    v-text-field(
43
                      outlined
44
                      v-model='config.host'
45
                      :label='$t(`admin:mail.smtpHost`)'
46 47
                      required
                      :counter='255'
48
                      prepend-icon='mdi-memory'
49 50
                      )
                    v-text-field(
51
                      outlined
52
                      v-model='config.port'
53
                      :label='$t(`admin:mail.smtpPort`)'
54
                      required
55
                      prepend-icon='mdi-serial-port'
56
                      persistent-hint
57
                      :hint='$t(`admin:mail.smtpPortHint`)'
58 59 60 61
                      style='max-width: 300px;'
                      )
                    v-switch(
                      v-model='config.secure'
62
                      :label='$t(`admin:mail.smtpTLS`)'
63 64
                      color='primary'
                      persistent-hint
65
                      :hint='$t(`admin:mail.smtpTLSHint`)'
66
                      prepend-icon='mdi-security-network'
67
                      inset
68
                      )
69 70 71 72 73 74 75 76 77 78
                    v-switch(
                      v-model='config.verifySSL'
                      :label='$t(`admin:mail.smtpVerifySSL`)'
                      color='primary'
                      persistent-hint
                      :hint='$t(`admin:mail.smtpVerifySSLHint`)'
                      prepend-icon='mdi-security-network'
                      inset
                      )
                    v-text-field.mt-8(
79
                      outlined
80
                      v-model='config.user'
81
                      :label='$t(`admin:mail.smtpUser`)'
82 83
                      required
                      :counter='255'
84
                      prepend-icon='mdi-shield-account-outline'
85 86
                      )
                    v-text-field(
87
                      outlined
88
                      v-model='config.pass'
89
                      :label='$t(`admin:mail.smtpPwd`)'
90
                      required
91
                      prepend-icon='mdi-form-textbox-password'
92 93 94 95
                      type='password'
                      )

            v-flex(lg6 xs12)
96
              v-card.animated.fadeInUp.wait-p2s
97 98
                v-form
                  v-toolbar(color='primary', dark, dense, flat)
99
                    v-toolbar-title.subtitle-1 {{ $t('admin:mail.dkim') }}
NGPixel's avatar
NGPixel committed
100 101
                  v-card-info
                    span {{ $t('admin:mail.dkimHint') }}
102
                  .pa-4
103 104
                    v-switch(
                      v-model='config.useDKIM'
105
                      :label='$t(`admin:mail.dkimUse`)'
106
                      color='primary'
107
                      prepend-icon='mdi-key'
108
                      inset
109 110
                      )
                    v-text-field(
111
                      outlined
112
                      v-model='config.dkimDomainName'
113
                      :label='$t(`admin:mail.dkimDomainName`)'
114
                      :counter='255'
115
                      prepend-icon='mdi-key'
116 117 118
                      :disabled='!config.useDKIM'
                      )
                    v-text-field(
119
                      outlined
120
                      v-model='config.dkimKeySelector'
121
                      :label='$t(`admin:mail.dkimKeySelector`)'
122
                      :counter='255'
123
                      prepend-icon='mdi-key'
124 125
                      :disabled='!config.useDKIM'
                      )
126
                    v-textarea(
127
                      outlined
128
                      v-model='config.dkimPrivateKey'
129
                      :label='$t(`admin:mail.dkimPrivateKey`)'
130
                      prepend-icon='mdi-key'
131
                      persistent-hint
132
                      :hint='$t(`admin:mail.dkimPrivateKeyHint`)'
133 134 135
                      :disabled='!config.useDKIM'
                      )

136
              v-card.mt-3.animated.fadeInUp.wait-p3s
137 138
                v-form
                  v-toolbar(color='teal', dark, dense, flat)
139 140
                    v-toolbar-title.subtitle-1 {{ $t('admin:mail.test') }}
                  .pa-4
141 142
                    .body-2.grey--text.text--darken-2 {{ $t('admin:mail.testHint') }}
                    v-text-field.mt-3(
143
                      outlined
144 145 146
                      v-model='testEmail'
                      :label='$t(`admin:mail.testRecipient`)'
                      :counter='255'
147
                      prepend-icon='mdi-email-outline'
148
                      :disabled='testLoading'
149 150 151
                      )
                  v-card-chin
                    v-spacer
152 153 154
                    v-btn.px-4(color='teal', dark, @click='sendTest', :loading='testLoading')
                      v-icon(left) mdi-send
                      span {{ $t('admin:mail.testSend') }}
155

156 157 158 159 160 161
</template>

<script>
import _ from 'lodash'
import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql'
import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql'
162
import mailTestMutation from 'gql/admin/mail/mail-mutation-sendtest.gql'
163 164 165 166 167 168 169 170 171 172

export default {
  data() {
    return {
      config: {
        senderName: '',
        senderEmail: '',
        host: '',
        port: 0,
        secure: false,
173
        verifySSL: false,
174 175 176 177 178 179
        user: '',
        pass: '',
        useDKIM: false,
        dkimDomainName: '',
        dkimKeySelector: '',
        dkimPrivateKey: ''
180
      },
181 182
      testEmail: '',
      testLoading: false
183 184 185 186 187 188 189 190 191 192 193 194 195
    }
  },
  methods: {
    async save () {
      try {
        await this.$apollo.mutate({
          mutation: mailUpdateConfigMutation,
          variables: {
            senderName: this.config.senderName || '',
            senderEmail: this.config.senderEmail || '',
            host: this.config.host || '',
            port: _.toSafeInteger(this.config.port) || 0,
            secure: this.config.secure || false,
196
            verifySSL: this.config.verifySSL || false,
197 198 199 200 201 202 203 204 205 206 207 208 209
            user: this.config.user || '',
            pass: this.config.pass || '',
            useDKIM: this.config.useDKIM || false,
            dkimDomainName: this.config.dkimDomainName || '',
            dkimKeySelector: this.config.dkimKeySelector || '',
            dkimPrivateKey: this.config.dkimPrivateKey || ''
          },
          watchLoading (isLoading) {
            this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-update')
          }
        })
        this.$store.commit('showNotification', {
          style: 'success',
210
          message: this.$t('admin:mail.saveSuccess'),
211 212 213
          icon: 'check'
        })
      } catch (err) {
214
        this.$store.commit('pushGraphError', err)
215
      }
216 217 218 219 220 221 222 223 224 225 226 227 228
    },
    async sendTest () {
      try {
        const resp = await this.$apollo.mutate({
          mutation: mailTestMutation,
          variables: {
            recipientEmail: this.testEmail
          },
          watchLoading (isLoading) {
            this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-test')
          }
        })
        if (!_.get(resp, 'data.mail.sendTest.responseResult.succeeded', false)) {
229
          throw new Error(_.get(resp, 'data.mail.sendTest.responseResult.message', 'An unexpected error occurred.'))
230 231 232 233 234 235 236 237 238 239 240
        }

        this.testEmail = ''
        this.$store.commit('showNotification', {
          style: 'success',
          message: this.$t('admin:mail.sendTestSuccess'),
          icon: 'check'
        })
      } catch (err) {
        this.$store.commit('pushGraphError', err)
      }
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    }
  },
  apollo: {
    config: {
      query: mailConfigQuery,
      fetchPolicy: 'network-only',
      update: (data) => _.cloneDeep(data.mail.config),
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-mail-refresh')
      }
    }
  }
}
</script>

<style lang='scss'>

</style>