diff --git a/components/admin/SMTP.vue b/components/admin/SMTP.vue index b866a446..de1cc016 100644 --- a/components/admin/SMTP.vue +++ b/components/admin/SMTP.vue @@ -4,22 +4,34 @@ v-card-text p(v-html="$t('admin.smtp_description')") v-form(v-model='isValid') + v-text-field(v-model='admin_email' @blur="save('admin_email', admin_email )" - :label="$t('admin.admin_email')" + :label="$t('admin.sender_email')" :rules="$validators.email") - v-text-field(v-model='smtp.host' - :label="$t('admin.smtp_hostname')" - :rules="[$validators.required('admin.smtp_hostname')]") - v-text-field(v-model='smtp.auth.user' - :label="$t('common.user')" - :rules="[$validators.required('common.user')]") + v-switch(v-model='smtp.sendmail' + :label="$t('admin.smtp_use_sendmail')") - v-text-field(v-model='smtp.auth.pass' - :label="$t('common.password')" - :rules="[$validators.required('common.password')]" - type='password') + template(v-if='!smtp.sendmail') + + v-text-field(v-model='smtp.host' + :label="$t('admin.smtp_hostname')" + :rules="[$validators.required('admin.smtp_hostname')]") + + v-text-field(v-model='smtp.port' + :label="$t('admin.smtp_port')" + :rules="[$validators.required('admin.smtp_port')]") + + v-switch(v-model='smtp.secure' + :label="$t('admin.smtp_secure')") + + v-text-field(v-model='smtp.auth.user' + :label="$t('common.user')") + + v-text-field(v-model='smtp.auth.pass' + :label="$t('common.password')" + type='password') v-card-actions v-spacer @@ -31,14 +43,16 @@ import { mapActions, mapState } from 'vuex' export default { data ({ $store }) { - const smtp = { host: '', auth: { user: '', pass: '' } } - 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 - } - } + const smtp = { auth: {}, ...$store.state.settings.smtp } + // 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 = {} + // } + // } return { isValid: false, loading: false, @@ -47,13 +61,28 @@ export default { } }, computed: mapState(['settings']), + watch: { + 'smtp.secure' (value) { + this.smtp.port = value ? 465 : 25 + } + }, methods: { ...mapActions(['setSetting']), async testSMTP () { this.loading = true try { - await this.setSetting({ key: 'smtp', value: this.smtp }) - await this.$axios.$post('/settings/smtp', { smtp: this.smtp }) + const smtp = JSON.parse(JSON.stringify(this.smtp)) + console.error(smtp) + if (!smtp.auth.user) { + console.error('ma non sono qui dentro !??!') + 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 }) this.$root.$message(this.$t('admin.smtp_test_success', { admin_email: this.admin_email }), { color: 'success' }) } catch (e) { console.error(e) @@ -67,9 +96,15 @@ export default { } }, done () { - if (this.smtp.auth.pass) { - this.setSetting({ key: 'smtp', value: JSON.parse(JSON.stringify(this.smtp)) }) + const smtp = JSON.parse(JSON.stringify(this.smtp)) + if (!smtp.auth.user) { + delete smtp.auth } + if (!smtp.secure) { + smtp.secure = false + smtp.ignoreTLS = true + } + this.setSetting({ key: 'smtp', value: smtp }) this.$emit('close') }, diff --git a/components/admin/Settings.vue b/components/admin/Settings.vue index 7c1e6dc5..332750c4 100644 --- a/components/admin/Settings.vue +++ b/components/admin/Settings.vue @@ -85,7 +85,8 @@ export default { computed: { ...mapState(['settings']), showSMTPAlert () { - return !this.setup && (!this.settings.admin_email || !this.settings.smtp || !this.settings.smtp.host || !this.settings.smtp.auth.user) + return !this.setup && + (!this.settings.admin_email || !this.settings.smtp || (!this.settings.smtp.sendmail && !this.settings.smtp.host)) }, instance_locale: { get () { return this.settings.instance_locale }, diff --git a/locales/en.json b/locales/en.json index 29228af6..8d1da0e4 100644 --- a/locales/en.json +++ b/locales/en.json @@ -229,10 +229,13 @@ "new_announcement": "New announcement", "show_smtp_setup": "Email settings", "smtp_hostname": "SMTP Hostname", + "smtp_port": "SMTP Port", + "smtp_secure": "SMTP Secure (TLS or STARTTLS)", "smtp_description": "