gancio-upstream/components/admin/SMTP.vue

78 lines
2.4 KiB
Vue
Raw Normal View History

2021-10-18 11:26:44 +02:00
<template lang="pug">
v-card
v-card-title SMTP Email configuration
v-card-text
p(v-html="$t('admin.smtp_description')")
2021-10-18 15:43:29 +02:00
v-form(v-model='isValid')
v-text-field(v-model='admin_email'
2021-10-19 16:37:28 +02:00
@blur="save('admin_email', admin_email )"
2021-10-18 15:43:29 +02:00
:label="$t('admin.admin_email')"
:rules="$validators.email")
v-text-field(v-model='smtp.host'
:label="$t('admin.smtp_hostname')"
:rules="[$validators.required('admin.smtp_hostname')]")
2021-10-18 11:26:44 +02:00
2021-10-18 15:43:29 +02:00
v-text-field(v-model='smtp.auth.user'
:label="$t('common.user')"
:rules="[$validators.required('common.user')]")
2021-10-18 11:26:44 +02:00
2021-10-18 15:43:29 +02:00
v-text-field(v-model='smtp.auth.pass'
:label="$t('common.password')"
:rules="[$validators.required('common.password')]"
type='password')
2021-10-18 11:26:44 +02:00
v-card-actions
v-spacer
2021-10-18 15:43:29 +02:00
v-btn(color='primary' @click='testSMTP' :loading='loading' :disabled='loading || !isValid') {{$t('admin.smtp_test_button')}}
2021-10-18 11:26:44 +02:00
v-btn(color='warning' @click="done") {{$t("common.ok")}}
</template>
<script>
import { mapActions, mapState } from 'vuex'
export default {
2021-10-19 16:37:28 +02:00
data ({ $store }) {
const smtp = { host: '', auth: { user: '', pass: '' } }
2021-10-21 17:03:01 +02:00
if ($store.state.settings.smtp) {
2021-10-19 16:37:28 +02:00
smtp.host = $store.state.settings.smtp.host
2021-10-21 17:03:01 +02:00
if ($store.state.settings.smtp.auth) {
smtp.auth.user = $store.state.settings.smtp.auth.user
smtp.auth.pass = $store.state.settings.smtp.auth.pass
}
2021-10-19 16:37:28 +02:00
}
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,
2021-10-19 16:37:28 +02:00
smtp,
admin_email: $store.state.settings.admin_email || ''
2021-10-18 15:43:29 +02:00
}
2021-10-18 11:26:44 +02:00
},
2021-10-19 16:37:28 +02:00
computed: mapState(['settings']),
2021-10-18 11:26:44 +02:00
methods: {
...mapActions(['setSetting']),
async testSMTP () {
this.loading = true
try {
2021-10-21 12:17:22 +02:00
this.setSetting({ key: 'smtp', value: this.smtp })
2021-10-18 11:26:44 +02:00
await this.$axios.$post('/settings/smtp', { smtp: this.smtp })
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 () {
2022-02-02 00:27:31 +01:00
if (this.smtp.auth.pass) {
this.setSetting({ key: 'smtp', value: JSON.parse(JSON.stringify(this.smtp)) })
}
2021-10-18 11:26:44 +02:00
this.$emit('close')
},
}
}
</script>