Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 2 | <b-modal |
| 3 | id="modal-settings" |
| 4 | ref="modal" |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 5 | :title="$t('pageLocalUserManagement.accountPolicySettings')" |
| 6 | :ok-title="$t('global.action.save')" |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 7 | @ok="onOk" |
| 8 | @hidden="resetForm" |
| 9 | > |
| 10 | <b-form novalidate @submit="handleSubmit"> |
| 11 | <b-container> |
| 12 | <b-row> |
| 13 | <b-col> |
| 14 | <b-form-group |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 15 | :label=" |
| 16 | $t('pageLocalUserManagement.modal.maxFailedLoginAttempts') |
| 17 | " |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 18 | label-for="lockout-threshold" |
| 19 | > |
| 20 | <b-form-text id="lockout-threshold-help-block"> |
| 21 | {{ |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 22 | $t('global.form.valueMustBeBetween', { |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 23 | min: 0, |
| 24 | max: 65535 |
| 25 | }) |
| 26 | }} |
| 27 | </b-form-text> |
| 28 | <b-form-input |
| 29 | id="lockout-threshold" |
| 30 | v-model.number="form.lockoutThreshold" |
| 31 | type="number" |
| 32 | aria-describedby="lockout-threshold-help-block" |
| 33 | :state="getValidationState($v.form.lockoutThreshold)" |
| 34 | @input="$v.form.lockoutThreshold.$touch()" |
| 35 | /> |
| 36 | <b-form-invalid-feedback role="alert"> |
| 37 | <template v-if="!$v.form.lockoutThreshold.required"> |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 38 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 39 | </template> |
| 40 | <template |
| 41 | v-if=" |
| 42 | !$v.form.lockoutThreshold.minLength || |
| 43 | !$v.form.lockoutThreshold.maxLength |
| 44 | " |
| 45 | > |
| 46 | {{ |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 47 | $t('global.form.valueMustBeBetween', { |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 48 | min: 0, |
| 49 | max: 65535 |
| 50 | }) |
| 51 | }} |
| 52 | </template> |
| 53 | </b-form-invalid-feedback> |
| 54 | </b-form-group> |
| 55 | </b-col> |
| 56 | <b-col> |
| 57 | <b-form-group |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 58 | :label="$t('pageLocalUserManagement.modal.userUnlockMethod')" |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 59 | > |
| 60 | <b-form-radio |
| 61 | v-model="form.unlockMethod" |
| 62 | name="unlock-method" |
| 63 | class="mb-2" |
| 64 | :value="0" |
| 65 | @input="$v.form.unlockMethod.$touch()" |
| 66 | > |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 67 | {{ $t('pageLocalUserManagement.modal.manual') }} |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 68 | </b-form-radio> |
| 69 | <b-form-radio |
| 70 | v-model="form.unlockMethod" |
| 71 | name="unlock-method" |
| 72 | :value="1" |
| 73 | @input="$v.form.unlockMethod.$touch()" |
| 74 | > |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 75 | {{ $t('pageLocalUserManagement.modal.automaticAfterTimeout') }} |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 76 | </b-form-radio> |
| 77 | <div class="mt-3 ml-4"> |
| 78 | <b-form-text id="lockout-duration-help-block"> |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 79 | {{ |
| 80 | $t('pageLocalUserManagement.modal.timeoutDurationSeconds') |
| 81 | }} |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 82 | </b-form-text> |
| 83 | <b-form-input |
| 84 | v-model.number="form.lockoutDuration" |
| 85 | aria-describedby="lockout-duration-help-block" |
| 86 | type="number" |
| 87 | :state="getValidationState($v.form.lockoutDuration)" |
| 88 | :readonly="$v.form.unlockMethod.$model === 0" |
| 89 | @input="$v.form.lockoutDuration.$touch()" |
| 90 | /> |
| 91 | <b-form-invalid-feedback role="alert"> |
| 92 | <template v-if="!$v.form.lockoutDuration.required"> |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 93 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 94 | </template> |
| 95 | <template v-else-if="!$v.form.lockoutDuration.minvalue"> |
Yoshie Muranaka | 547b5fc | 2020-02-24 15:42:40 -0800 | [diff] [blame] | 96 | {{ $t('global.form.mustBeAtLeast', { value: 1 }) }} |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 97 | </template> |
| 98 | </b-form-invalid-feedback> |
| 99 | </div> |
| 100 | </b-form-group> |
| 101 | </b-col> |
| 102 | </b-row> |
| 103 | </b-container> |
| 104 | </b-form> |
| 105 | </b-modal> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 106 | </template> |
| 107 | |
| 108 | <script> |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 109 | import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js'; |
| 110 | import { |
| 111 | required, |
| 112 | requiredIf, |
| 113 | minValue, |
| 114 | maxValue |
| 115 | } from 'vuelidate/lib/validators'; |
| 116 | |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 117 | export default { |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 118 | mixins: [VuelidateMixin], |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 119 | props: { |
| 120 | settings: { |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 121 | type: Object, |
| 122 | required: true |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 123 | } |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 124 | }, |
| 125 | data() { |
| 126 | return { |
| 127 | form: { |
| 128 | lockoutThreshold: 0, |
| 129 | unlockMethod: 0, |
| 130 | lockoutDuration: null |
| 131 | } |
| 132 | }; |
| 133 | }, |
| 134 | watch: { |
| 135 | settings: function({ lockoutThreshold, lockoutDuration }) { |
| 136 | this.form.lockoutThreshold = lockoutThreshold; |
| 137 | this.form.unlockMethod = lockoutDuration ? 1 : 0; |
| 138 | this.form.lockoutDuration = lockoutDuration ? lockoutDuration : null; |
| 139 | } |
| 140 | }, |
| 141 | validations: { |
| 142 | form: { |
| 143 | lockoutThreshold: { |
| 144 | minValue: minValue(0), |
| 145 | maxValue: maxValue(65535), |
| 146 | required |
| 147 | }, |
| 148 | unlockMethod: { required }, |
| 149 | lockoutDuration: { |
| 150 | minValue: function(value) { |
| 151 | return this.form.unlockMethod === 0 || value > 0; |
| 152 | }, |
| 153 | required: requiredIf(function() { |
| 154 | return this.form.unlockMethod === 1; |
| 155 | }) |
| 156 | } |
| 157 | } |
| 158 | }, |
| 159 | methods: { |
| 160 | handleSubmit() { |
| 161 | this.$v.$touch(); |
| 162 | if (this.$v.$invalid) return; |
| 163 | |
| 164 | let lockoutThreshold; |
| 165 | let lockoutDuration; |
| 166 | if (this.$v.form.lockoutThreshold.$dirty) { |
| 167 | lockoutThreshold = this.form.lockoutThreshold; |
| 168 | } |
| 169 | if (this.$v.form.unlockMethod.$dirty) { |
| 170 | lockoutDuration = this.form.unlockMethod |
| 171 | ? this.form.lockoutDuration |
| 172 | : 0; |
| 173 | } |
| 174 | |
| 175 | this.$emit('ok', { lockoutThreshold, lockoutDuration }); |
| 176 | this.closeModal(); |
| 177 | }, |
| 178 | onOk(bvModalEvt) { |
| 179 | // prevent modal close |
| 180 | bvModalEvt.preventDefault(); |
| 181 | this.handleSubmit(); |
| 182 | }, |
| 183 | closeModal() { |
| 184 | this.$nextTick(() => { |
| 185 | this.$refs.modal.hide(); |
| 186 | }); |
| 187 | }, |
| 188 | resetForm() { |
| 189 | // Reset form models |
| 190 | this.form.lockoutThreshold = this.settings.lockoutThreshold; |
| 191 | this.form.unlockMethod = this.settings.lockoutDuration ? 1 : 0; |
| 192 | this.form.lockoutDuration = this.settings.lockoutDuration |
| 193 | ? this.settings.lockoutDuration |
| 194 | : null; |
| 195 | this.$v.$reset(); // clear validations |
| 196 | } |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 197 | } |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 198 | }; |
| 199 | </script> |