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