blob: a611c590d49a25eb4487c60f1cd646687bfba3ab [file] [log] [blame]
Yoshie Muranaka463a5702019-12-04 09:09:36 -08001<template>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08002 <b-modal
3 id="modal-settings"
4 ref="modal"
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -08005 :title="$t('pageLocalUserManagement.accountPolicySettings')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08006 @hidden="resetForm"
7 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -07008 <b-form id="form-settings" novalidate @submit.prevent="handleSubmit">
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08009 <b-container>
10 <b-row>
11 <b-col>
12 <b-form-group
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080013 :label="
14 $t('pageLocalUserManagement.modal.maxFailedLoginAttempts')
15 "
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080016 label-for="lockout-threshold"
17 >
18 <b-form-text id="lockout-threshold-help-block">
19 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080020 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080021 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 Wolmersfe1e6582020-07-15 11:18:12 -050031 data-test-id="localUserManagement-input-lockoutThreshold"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080032 :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 Muranaka547b5fc2020-02-24 15:42:40 -080037 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080038 </template>
39 <template
40 v-if="
41 !$v.form.lockoutThreshold.minLength ||
42 !$v.form.lockoutThreshold.maxLength
43 "
44 >
45 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080046 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080047 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 Muranaka547b5fc2020-02-24 15:42:40 -080057 :label="$t('pageLocalUserManagement.modal.userUnlockMethod')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080058 >
59 <b-form-radio
60 v-model="form.unlockMethod"
61 name="unlock-method"
62 class="mb-2"
63 :value="0"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050064 data-test-id="localUserManagement-radio-manualUnlock"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080065 @input="$v.form.unlockMethod.$touch()"
66 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080067 {{ $t('pageLocalUserManagement.modal.manual') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080068 </b-form-radio>
69 <b-form-radio
70 v-model="form.unlockMethod"
71 name="unlock-method"
72 :value="1"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050073 data-test-id="localUserManagement-radio-automaticUnlock"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080074 @input="$v.form.unlockMethod.$touch()"
75 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080076 {{ $t('pageLocalUserManagement.modal.automaticAfterTimeout') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080077 </b-form-radio>
78 <div class="mt-3 ml-4">
79 <b-form-text id="lockout-duration-help-block">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080080 {{
81 $t('pageLocalUserManagement.modal.timeoutDurationSeconds')
82 }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080083 </b-form-text>
84 <b-form-input
85 v-model.number="form.lockoutDuration"
86 aria-describedby="lockout-duration-help-block"
87 type="number"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050088 data-test-id="localUserManagement-input-lockoutDuration"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080089 :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 Muranaka547b5fc2020-02-24 15:42:40 -080095 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080096 </template>
97 <template v-else-if="!$v.form.lockoutDuration.minvalue">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080098 {{ $t('global.form.mustBeAtLeast', { value: 1 }) }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080099 </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 Muranaka9a9092d2020-05-04 08:24:21 -0700107 <template v-slot:modal-footer="{ ok, cancel }">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500108 <b-button
109 variant="secondary"
110 data-test-id="localUserManagement-button-cancel"
111 @click="cancel()"
112 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700113 {{ $t('global.action.cancel') }}
114 </b-button>
115 <b-button
116 form="form-settings"
117 type="submit"
118 variant="primary"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500119 data-test-id="localUserManagement-button-submit"
Yoshie Muranaka7f7687e2020-08-12 09:13:44 -0700120 @click="onOk"
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700121 >
122 {{ $t('global.action.save') }}
123 </b-button>
124 </template>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800125 </b-modal>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800126</template>
127
128<script>
SurenNeware61859092020-10-01 09:37:32 +0530129import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800130import {
131 required,
132 requiredIf,
133 minValue,
134 maxValue
135} from 'vuelidate/lib/validators';
136
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800137export default {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800138 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600139 props: {
140 settings: {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800141 type: Object,
142 required: true
Derick Montague09e45cd2020-01-23 15:45:57 -0600143 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800144 },
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 Montague09e45cd2020-01-23 15:45:57 -0600217 }
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800218};
219</script>