gancio-upstream/components/admin/SMTP.vue

116 lines
3.4 KiB
Vue
Raw Normal View History

2021-10-18 11:26:44 +02:00
<template lang="pug">
2022-07-01 15:55:09 +02:00
v-card
v-card-title SMTP Email configuration
v-card-text
p(v-html="$t('admin.smtp_description')")
v-form(v-model='isValid')
2022-07-01 15:55:09 +02:00
v-text-field(v-model='admin_email'
@blur="save('admin_email', admin_email )"
:label="$t('admin.sender_email')"
:rules="$validators.email")
2021-10-18 11:26:44 +02:00
2022-07-01 15:55:09 +02:00
v-switch(v-model='smtp.sendmail'
:label="$t('admin.smtp_use_sendmail')")
2022-07-01 15:55:09 +02:00
v-row(v-if='!smtp.sendmail')
v-col(cols=12 md=9)
v-text-field(v-model='smtp.host'
:label="$t('admin.smtp_hostname')"
:rules="[$validators.required('admin.smtp_hostname')]")
v-col(cols=12 md=3)
v-text-field(v-model='smtp.port'
:label="$t('admin.smtp_port')"
:rules="[$validators.required('admin.smtp_port')]")
2022-07-01 15:55:09 +02:00
v-col(cols=12)
v-switch(v-model='smtp.secure'
:label="$t('admin.smtp_secure')")
v-col(md=6)
v-text-field(v-model='smtp.auth.user'
:label="$t('common.user')")
2022-07-01 15:55:09 +02:00
v-col(md=6)
v-text-field(v-model='smtp.auth.pass'
:label="$t('common.password')"
type='password')
v-card-actions
v-spacer
v-btn(color='primary' @click='testSMTP' :loading='loading' :disabled='loading || !isValid' outlined) {{$t('admin.smtp_test_button')}}
v-btn(color='warning' @click="done" outlined) {{$t("common.ok")}}
2021-10-18 11:26:44 +02:00
</template>
<script>
import { mapActions, mapState } from 'vuex'
export default {
2021-10-19 16:37:28 +02:00
data ({ $store }) {
// if ($store.state.settings.smtp) {
// smtp.host = $store.state.settings.smtp.host
// if ($store.state.settings.smtp.auth) {
// smtp.auth.user = $store.state.settings.smtp.auth.user
// smtp.auth.pass = $store.state.settings.smtp.auth.pass
// } else {
// smtp.auth = {}
// }
// }
2021-10-18 11:26:44 +02:00
return {
2021-10-18 15:43:29 +02:00
isValid: false,
2021-10-18 11:26:44 +02:00
loading: false,
2022-07-18 10:05:59 +02:00
smtp: { auth: {} },
2021-10-19 16:37:28 +02:00
admin_email: $store.state.settings.admin_email || ''
2021-10-18 15:43:29 +02:00
}
2021-10-18 11:26:44 +02:00
},
2022-07-18 10:05:59 +02:00
async fetch () {
this.smtp = await this.$axios.$get('/settings/smtp')
},
2021-10-19 16:37:28 +02:00
computed: mapState(['settings']),
watch: {
'smtp.secure' (value) {
this.smtp.port = value ? 465 : 25
}
},
2021-10-18 11:26:44 +02:00
methods: {
...mapActions(['setSetting']),
async testSMTP () {
this.loading = true
try {
const smtp = JSON.parse(JSON.stringify(this.smtp))
if (!smtp.auth.user) {
delete smtp.auth
}
if (!smtp.secure) {
smtp.secure = false
smtp.ignoreTLS = true
}
// await this.setSetting({ key: 'smtp', value: JSON.parse(JSON.stringify(this.smtp)) })
await this.$axios.$post('/settings/smtp', { smtp })
2021-10-18 11:26:44 +02:00
this.$root.$message(this.$t('admin.smtp_test_success', { admin_email: this.admin_email }), { color: 'success' })
} catch (e) {
console.error(e)
this.$root.$message(e.response && e.response.data, { color: 'error' })
}
this.loading = false
},
2021-10-19 16:37:28 +02:00
save (key, value) {
if (this.settings[key] !== value) {
this.setSetting({ key, value })
}
},
2021-10-18 11:26:44 +02:00
done () {
const smtp = JSON.parse(JSON.stringify(this.smtp))
if (!smtp.auth.user) {
delete smtp.auth
}
if (!smtp.secure) {
smtp.secure = false
smtp.ignoreTLS = true
2022-02-02 00:27:31 +01:00
}
this.setSetting({ key: 'smtp', value: smtp })
2021-10-18 11:26:44 +02:00
this.$emit('close')
},
}
}
</script>