better smtp setup, allow local sendmail, add secure flag, auth not required

This commit is contained in:
lesion
2022-06-23 13:07:46 +02:00
parent b436ff4772
commit 1862e0cb60
4 changed files with 65 additions and 26 deletions

View File

@@ -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')
},

View File

@@ -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 },