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