admin-mail.vue 8.97 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
Nick's avatar
Nick committed
6
          img.animated.fadeInUp(src='/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-contact-mail'
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-at'
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
                      )
                    v-text-field.mt-3(
70
                      outlined
71
                      v-model='config.user'
72
                      :label='$t(`admin:mail.smtpUser`)'
73 74
                      required
                      :counter='255'
75
                      prepend-icon='mdi-shield-account-outline'
76 77
                      )
                    v-text-field(
78
                      outlined
79
                      v-model='config.pass'
80
                      :label='$t(`admin:mail.smtpPwd`)'
81
                      required
82
                      prepend-icon='mdi-textbox-password'
83 84 85 86
                      type='password'
                      )

            v-flex(lg6 xs12)
87
              v-card.animated.fadeInUp.wait-p2s
88 89
                v-form
                  v-toolbar(color='primary', dark, dense, flat)
90 91
                    v-toolbar-title.subtitle-1 {{ $t('admin:mail.dkim') }}
                  .pa-4
92
                    .body-2.grey--text.text--darken-2 {{ $t('admin:mail.dkimHint') }}
93 94
                    v-switch(
                      v-model='config.useDKIM'
95
                      :label='$t(`admin:mail.dkimUse`)'
96
                      color='primary'
97
                      prepend-icon='mdi-key'
98
                      inset
99 100
                      )
                    v-text-field(
101
                      outlined
102
                      v-model='config.dkimDomainName'
103
                      :label='$t(`admin:mail.dkimDomainName`)'
104
                      :counter='255'
105
                      prepend-icon='mdi-key'
106 107 108
                      :disabled='!config.useDKIM'
                      )
                    v-text-field(
109
                      outlined
110
                      v-model='config.dkimKeySelector'
111
                      :label='$t(`admin:mail.dkimKeySelector`)'
112
                      :counter='255'
113
                      prepend-icon='mdi-key'
114 115
                      :disabled='!config.useDKIM'
                      )
116
                    v-textarea(
117
                      outlined
118
                      v-model='config.dkimPrivateKey'
119
                      :label='$t(`admin:mail.dkimPrivateKey`)'
120
                      prepend-icon='mdi-key'
121
                      persistent-hint
122
                      :hint='$t(`admin:mail.dkimPrivateKeyHint`)'
123 124 125
                      :disabled='!config.useDKIM'
                      )

126
              v-card.mt-3.animated.fadeInUp.wait-p3s
127 128
                v-form
                  v-toolbar(color='teal', dark, dense, flat)
129 130
                    v-toolbar-title.subtitle-1 {{ $t('admin:mail.test') }}
                  .pa-4
131 132
                    .body-2.grey--text.text--darken-2 {{ $t('admin:mail.testHint') }}
                    v-text-field.mt-3(
133
                      outlined
134 135 136
                      v-model='testEmail'
                      :label='$t(`admin:mail.testRecipient`)'
                      :counter='255'
137
                      prepend-icon='mdi-email-outline'
138
                      :disabled='testLoading'
139 140 141
                      )
                  v-card-chin
                    v-spacer
142 143 144
                    v-btn.px-4(color='teal', dark, @click='sendTest', :loading='testLoading')
                      v-icon(left) mdi-send
                      span {{ $t('admin:mail.testSend') }}
145

146 147 148 149
</template>

<script>
import _ from 'lodash'
Nick's avatar
Nick committed
150
import { get } from 'vuex-pathify'
151 152
import mailConfigQuery from 'gql/admin/mail/mail-query-config.gql'
import mailUpdateConfigMutation from 'gql/admin/mail/mail-mutation-save-config.gql'
153
import mailTestMutation from 'gql/admin/mail/mail-mutation-sendtest.gql'
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

export default {
  data() {
    return {
      config: {
        senderName: '',
        senderEmail: '',
        host: '',
        port: 0,
        secure: false,
        user: '',
        pass: '',
        useDKIM: false,
        dkimDomainName: '',
        dkimKeySelector: '',
        dkimPrivateKey: ''
170
      },
171 172
      testEmail: '',
      testLoading: false
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    }
  },
  computed: {
    darkMode: get('site/dark')
  },
  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,
            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',
202
          message: this.$t('admin:mail.saveSuccess'),
203 204 205
          icon: 'check'
        })
      } catch (err) {
206
        this.$store.commit('pushGraphError', err)
207
      }
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    },
    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)) {
          throw new Error(_.get(resp, 'data.mail.sendTest.responseResult.message', 'An unexpected error occured.'))
        }

        this.testEmail = ''
        this.$store.commit('showNotification', {
          style: 'success',
          message: this.$t('admin:mail.sendTestSuccess'),
          icon: 'check'
        })
      } catch (err) {
        this.$store.commit('pushGraphError', err)
      }
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    }
  },
  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>