blob: 405aa8cba8a803c81890040f7eca29a57a7f5cdb [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 @ok="onOk"
7 @hidden="resetForm"
8 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -07009 <b-form id="form-settings" novalidate @submit.prevent="handleSubmit">
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080010 <b-container>
11 <b-row>
12 <b-col>
13 <b-form-group
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080014 :label="
15 $t('pageLocalUserManagement.modal.maxFailedLoginAttempts')
16 "
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080017 label-for="lockout-threshold"
18 >
19 <b-form-text id="lockout-threshold-help-block">
20 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080021 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080022 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 Wolmersfe1e6582020-07-15 11:18:12 -050032 data-test-id="localUserManagement-input-lockoutThreshold"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080033 :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 Muranaka547b5fc2020-02-24 15:42:40 -080038 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080039 </template>
40 <template
41 v-if="
42 !$v.form.lockoutThreshold.minLength ||
43 !$v.form.lockoutThreshold.maxLength
44 "
45 >
46 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080047 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080048 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 Muranaka547b5fc2020-02-24 15:42:40 -080058 :label="$t('pageLocalUserManagement.modal.userUnlockMethod')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080059 >
60 <b-form-radio
61 v-model="form.unlockMethod"
62 name="unlock-method"
63 class="mb-2"
64 :value="0"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050065 data-test-id="localUserManagement-radio-manualUnlock"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080066 @input="$v.form.unlockMethod.$touch()"
67 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080068 {{ $t('pageLocalUserManagement.modal.manual') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080069 </b-form-radio>
70 <b-form-radio
71 v-model="form.unlockMethod"
72 name="unlock-method"
73 :value="1"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050074 data-test-id="localUserManagement-radio-automaticUnlock"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080075 @input="$v.form.unlockMethod.$touch()"
76 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080077 {{ $t('pageLocalUserManagement.modal.automaticAfterTimeout') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080078 </b-form-radio>
79 <div class="mt-3 ml-4">
80 <b-form-text id="lockout-duration-help-block">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080081 {{
82 $t('pageLocalUserManagement.modal.timeoutDurationSeconds')
83 }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080084 </b-form-text>
85 <b-form-input
86 v-model.number="form.lockoutDuration"
87 aria-describedby="lockout-duration-help-block"
88 type="number"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050089 data-test-id="localUserManagement-input-lockoutDuration"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080090 :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 Muranaka547b5fc2020-02-24 15:42:40 -080096 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080097 </template>
98 <template v-else-if="!$v.form.lockoutDuration.minvalue">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080099 {{ $t('global.form.mustBeAtLeast', { value: 1 }) }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800100 </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 Muranaka9a9092d2020-05-04 08:24:21 -0700108 <template v-slot:modal-footer="{ ok, cancel }">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500109 <b-button
110 variant="secondary"
111 data-test-id="localUserManagement-button-cancel"
112 @click="cancel()"
113 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700114 {{ $t('global.action.cancel') }}
115 </b-button>
116 <b-button
117 form="form-settings"
118 type="submit"
119 variant="primary"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500120 data-test-id="localUserManagement-button-submit"
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700121 @click="ok()"
122 >
123 {{ $t('global.action.save') }}
124 </b-button>
125 </template>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800126 </b-modal>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800127</template>
128
129<script>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800130import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js';
131import {
132 required,
133 requiredIf,
134 minValue,
135 maxValue
136} from 'vuelidate/lib/validators';
137
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800138export default {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800139 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600140 props: {
141 settings: {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800142 type: Object,
143 required: true
Derick Montague09e45cd2020-01-23 15:45:57 -0600144 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800145 },
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 Montague09e45cd2020-01-23 15:45:57 -0600218 }
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800219};
220</script>