blob: 2e41b2929ec956af2a44fd400fe57dbf9a7a2d36 [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"
5 :title="$t('localUserManagement.accountPolicySettings')"
6 :ok-title="$t('global.actions.save')"
7 @ok="onOk"
8 @hidden="resetForm"
9 >
10 <b-form novalidate @submit="handleSubmit">
11 <b-container>
12 <b-row>
13 <b-col>
14 <b-form-group
15 :label="$t('localUserManagement.modals.maxFailedLoginAttempts')"
16 label-for="lockout-threshold"
17 >
18 <b-form-text id="lockout-threshold-help-block">
19 {{
20 $t('global.formField.valueMustBeBetween', {
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"
31 :state="getValidationState($v.form.lockoutThreshold)"
32 @input="$v.form.lockoutThreshold.$touch()"
33 />
34 <b-form-invalid-feedback role="alert">
35 <template v-if="!$v.form.lockoutThreshold.required">
36 {{ $t('global.formField.fieldRequired') }}
37 </template>
38 <template
39 v-if="
40 !$v.form.lockoutThreshold.minLength ||
41 !$v.form.lockoutThreshold.maxLength
42 "
43 >
44 {{
45 $t('global.formField.valueMustBeBetween', {
46 min: 0,
47 max: 65535
48 })
49 }}
50 </template>
51 </b-form-invalid-feedback>
52 </b-form-group>
53 </b-col>
54 <b-col>
55 <b-form-group
56 :label="$t('localUserManagement.modals.userUnlockMethod')"
57 >
58 <b-form-radio
59 v-model="form.unlockMethod"
60 name="unlock-method"
61 class="mb-2"
62 :value="0"
63 @input="$v.form.unlockMethod.$touch()"
64 >
65 {{ $t('localUserManagement.modals.manual') }}
66 </b-form-radio>
67 <b-form-radio
68 v-model="form.unlockMethod"
69 name="unlock-method"
70 :value="1"
71 @input="$v.form.unlockMethod.$touch()"
72 >
73 {{ $t('localUserManagement.modals.automaticAfterTimeout') }}
74 </b-form-radio>
75 <div class="mt-3 ml-4">
76 <b-form-text id="lockout-duration-help-block">
77 {{ $t('localUserManagement.modals.timeoutDurationSeconds') }}
78 </b-form-text>
79 <b-form-input
80 v-model.number="form.lockoutDuration"
81 aria-describedby="lockout-duration-help-block"
82 type="number"
83 :state="getValidationState($v.form.lockoutDuration)"
84 :readonly="$v.form.unlockMethod.$model === 0"
85 @input="$v.form.lockoutDuration.$touch()"
86 />
87 <b-form-invalid-feedback role="alert">
88 <template v-if="!$v.form.lockoutDuration.required">
89 {{ $t('global.formField.fieldRequired') }}
90 </template>
91 <template v-else-if="!$v.form.lockoutDuration.minvalue">
92 {{ $t('global.formField.mustBeAtLeast', { value: 1 }) }}
93 </template>
94 </b-form-invalid-feedback>
95 </div>
96 </b-form-group>
97 </b-col>
98 </b-row>
99 </b-container>
100 </b-form>
101 </b-modal>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800102</template>
103
104<script>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800105import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js';
106import {
107 required,
108 requiredIf,
109 minValue,
110 maxValue
111} from 'vuelidate/lib/validators';
112
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800113export default {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800114 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600115 props: {
116 settings: {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800117 type: Object,
118 required: true
Derick Montague09e45cd2020-01-23 15:45:57 -0600119 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800120 },
121 data() {
122 return {
123 form: {
124 lockoutThreshold: 0,
125 unlockMethod: 0,
126 lockoutDuration: null
127 }
128 };
129 },
130 watch: {
131 settings: function({ lockoutThreshold, lockoutDuration }) {
132 this.form.lockoutThreshold = lockoutThreshold;
133 this.form.unlockMethod = lockoutDuration ? 1 : 0;
134 this.form.lockoutDuration = lockoutDuration ? lockoutDuration : null;
135 }
136 },
137 validations: {
138 form: {
139 lockoutThreshold: {
140 minValue: minValue(0),
141 maxValue: maxValue(65535),
142 required
143 },
144 unlockMethod: { required },
145 lockoutDuration: {
146 minValue: function(value) {
147 return this.form.unlockMethod === 0 || value > 0;
148 },
149 required: requiredIf(function() {
150 return this.form.unlockMethod === 1;
151 })
152 }
153 }
154 },
155 methods: {
156 handleSubmit() {
157 this.$v.$touch();
158 if (this.$v.$invalid) return;
159
160 let lockoutThreshold;
161 let lockoutDuration;
162 if (this.$v.form.lockoutThreshold.$dirty) {
163 lockoutThreshold = this.form.lockoutThreshold;
164 }
165 if (this.$v.form.unlockMethod.$dirty) {
166 lockoutDuration = this.form.unlockMethod
167 ? this.form.lockoutDuration
168 : 0;
169 }
170
171 this.$emit('ok', { lockoutThreshold, lockoutDuration });
172 this.closeModal();
173 },
174 onOk(bvModalEvt) {
175 // prevent modal close
176 bvModalEvt.preventDefault();
177 this.handleSubmit();
178 },
179 closeModal() {
180 this.$nextTick(() => {
181 this.$refs.modal.hide();
182 });
183 },
184 resetForm() {
185 // Reset form models
186 this.form.lockoutThreshold = this.settings.lockoutThreshold;
187 this.form.unlockMethod = this.settings.lockoutDuration ? 1 : 0;
188 this.form.lockoutDuration = this.settings.lockoutDuration
189 ? this.settings.lockoutDuration
190 : null;
191 this.$v.$reset(); // clear validations
192 }
Derick Montague09e45cd2020-01-23 15:45:57 -0600193 }
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800194};
195</script>