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