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