blob: 8727b20e5f6e1f64fb82ca72ef2c5d67e8be6541 [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"
32 :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"
64 @input="$v.form.unlockMethod.$touch()"
65 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080066 {{ $t('pageLocalUserManagement.modal.manual') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080067 </b-form-radio>
68 <b-form-radio
69 v-model="form.unlockMethod"
70 name="unlock-method"
71 :value="1"
72 @input="$v.form.unlockMethod.$touch()"
73 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080074 {{ $t('pageLocalUserManagement.modal.automaticAfterTimeout') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080075 </b-form-radio>
76 <div class="mt-3 ml-4">
77 <b-form-text id="lockout-duration-help-block">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080078 {{
79 $t('pageLocalUserManagement.modal.timeoutDurationSeconds')
80 }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080081 </b-form-text>
82 <b-form-input
83 v-model.number="form.lockoutDuration"
84 aria-describedby="lockout-duration-help-block"
85 type="number"
86 :state="getValidationState($v.form.lockoutDuration)"
87 :readonly="$v.form.unlockMethod.$model === 0"
88 @input="$v.form.lockoutDuration.$touch()"
89 />
90 <b-form-invalid-feedback role="alert">
91 <template v-if="!$v.form.lockoutDuration.required">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080092 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080093 </template>
94 <template v-else-if="!$v.form.lockoutDuration.minvalue">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080095 {{ $t('global.form.mustBeAtLeast', { value: 1 }) }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080096 </template>
97 </b-form-invalid-feedback>
98 </div>
99 </b-form-group>
100 </b-col>
101 </b-row>
102 </b-container>
103 </b-form>
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700104 <template v-slot:modal-footer="{ ok, cancel }">
105 <b-button variant="secondary" @click="cancel()">
106 {{ $t('global.action.cancel') }}
107 </b-button>
108 <b-button
109 form="form-settings"
110 type="submit"
111 variant="primary"
112 @click="ok()"
113 >
114 {{ $t('global.action.save') }}
115 </b-button>
116 </template>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800117 </b-modal>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800118</template>
119
120<script>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800121import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js';
122import {
123 required,
124 requiredIf,
125 minValue,
126 maxValue
127} from 'vuelidate/lib/validators';
128
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800129export default {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800130 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600131 props: {
132 settings: {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800133 type: Object,
134 required: true
Derick Montague09e45cd2020-01-23 15:45:57 -0600135 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800136 },
137 data() {
138 return {
139 form: {
140 lockoutThreshold: 0,
141 unlockMethod: 0,
142 lockoutDuration: null
143 }
144 };
145 },
146 watch: {
147 settings: function({ lockoutThreshold, lockoutDuration }) {
148 this.form.lockoutThreshold = lockoutThreshold;
149 this.form.unlockMethod = lockoutDuration ? 1 : 0;
150 this.form.lockoutDuration = lockoutDuration ? lockoutDuration : null;
151 }
152 },
153 validations: {
154 form: {
155 lockoutThreshold: {
156 minValue: minValue(0),
157 maxValue: maxValue(65535),
158 required
159 },
160 unlockMethod: { required },
161 lockoutDuration: {
162 minValue: function(value) {
163 return this.form.unlockMethod === 0 || value > 0;
164 },
165 required: requiredIf(function() {
166 return this.form.unlockMethod === 1;
167 })
168 }
169 }
170 },
171 methods: {
172 handleSubmit() {
173 this.$v.$touch();
174 if (this.$v.$invalid) return;
175
176 let lockoutThreshold;
177 let lockoutDuration;
178 if (this.$v.form.lockoutThreshold.$dirty) {
179 lockoutThreshold = this.form.lockoutThreshold;
180 }
181 if (this.$v.form.unlockMethod.$dirty) {
182 lockoutDuration = this.form.unlockMethod
183 ? this.form.lockoutDuration
184 : 0;
185 }
186
187 this.$emit('ok', { lockoutThreshold, lockoutDuration });
188 this.closeModal();
189 },
190 onOk(bvModalEvt) {
191 // prevent modal close
192 bvModalEvt.preventDefault();
193 this.handleSubmit();
194 },
195 closeModal() {
196 this.$nextTick(() => {
197 this.$refs.modal.hide();
198 });
199 },
200 resetForm() {
201 // Reset form models
202 this.form.lockoutThreshold = this.settings.lockoutThreshold;
203 this.form.unlockMethod = this.settings.lockoutDuration ? 1 : 0;
204 this.form.lockoutDuration = this.settings.lockoutDuration
205 ? this.settings.lockoutDuration
206 : null;
207 this.$v.$reset(); // clear validations
208 }
Derick Montague09e45cd2020-01-23 15:45:57 -0600209 }
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800210};
211</script>