From 37f6f72ff1ed6d4795c3f67ca2ba92367582e562 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Tue, 20 Sep 2022 13:30:30 +0300 Subject: add validation for snmp, smtp, syslog --- src/views/_sila/Settings/TransferInfo/Smtp.vue | 110 ++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 3 deletions(-) (limited to 'src/views/_sila/Settings/TransferInfo/Smtp.vue') diff --git a/src/views/_sila/Settings/TransferInfo/Smtp.vue b/src/views/_sila/Settings/TransferInfo/Smtp.vue index 34d171de..40a182d8 100644 --- a/src/views/_sila/Settings/TransferInfo/Smtp.vue +++ b/src/views/_sila/Settings/TransferInfo/Smtp.vue @@ -12,6 +12,7 @@ data-test-id="checkbox-authorization" switch :disabled="loading || isNotAdmin" + @change="onChangeAuthCheckbox($event)" > {{ $t('global.status.enabled') }} @@ -29,9 +30,23 @@ id="smtp-name" v-model="form.username" type="text" + :state="getValidationState($v.form.username)" :disabled="loading || isNotAdmin || !form.is_need_auth" - /> + @input="$v.form.username.$touch()" + /> + + + + + + + + + + @@ -55,8 +89,18 @@ + + + + @@ -68,8 +112,18 @@ id="smtp-port" v-model="form.port" type="number" + :state="getValidationState($v.form.port)" :disabled="loading || isNotAdmin" + @input="$v.form.port.$touch()" /> + + + + @@ -165,6 +219,16 @@ import LoadingBarMixin, { import IconAdd from '@carbon/icons-vue/es/add--alt/20'; import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; import InputPasswordToggle from '@/components/_sila/Global/InputPasswordToggle'; +import { + helpers, + ipAddress, + maxLength, + minLength, + required, + requiredIf, +} from 'vuelidate/lib/validators'; +import VuelidateMixin from '@/components/_sila/Mixins/VuelidateMixin.js'; +import { isoPortRegex } from '@/utilities/_sila/regexConstants'; export default { name: 'Smtp', @@ -175,7 +239,7 @@ export default { TableRowAction, InputPasswordToggle, }, - mixins: [BVToastMixin, LoadingBarMixin], + mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin], data() { return { @@ -236,7 +300,40 @@ export default { this.endLoader(); }); }, + validations() { + return { + form: { + username: { + required: requiredIf(function () { + return this.form.is_need_auth; + }), + maxLength: maxLength(16), + pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/), + }, + password: { + required: requiredIf(function () { + return this.form.is_need_auth; + }), + minLength: minLength(8), + maxLength: maxLength(20), + }, + host: { + required, + ipAddress, + }, + port: { + required, + pattern: helpers.regex('pattern', isoPortRegex), + }, + }, + }; + }, methods: { + onChangeAuthCheckbox($event) { + if (!$event) { + this.resetAuthForm(); + } + }, onTableAction($event, { host }) { if ($event === 'delete') { this.deleteSubscriber(host); @@ -254,6 +351,9 @@ export default { this.$bvModal.show('modal-smtp'); }, saveSmtp() { + this.$v.$touch(); + if (this.$v.$invalid) return; + this.startLoader(); if (!this.form.is_need_auth) { // eslint-disable-next-line no-unused-vars @@ -290,6 +390,10 @@ export default { this.form.is_need_auth = this.settings.is_need_auth; this.form.is_need_ssl = this.settings.is_need_ssl; }, + resetAuthForm() { + this.form.username = null; + this.form.password = null; + }, }, }; -- cgit v1.2.3