blob: 650cd56083305f57e4f69b042110de710d9f818d [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')"
6 :ok-title="$t('global.action.save')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08007 @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
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080015 :label="
16 $t('pageLocalUserManagement.modal.maxFailedLoginAttempts')
17 "
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080018 label-for="lockout-threshold"
19 >
20 <b-form-text id="lockout-threshold-help-block">
21 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080022 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080023 min: 0,
24 max: 65535
25 })
26 }}
27 </b-form-text>
28 <b-form-input
29 id="lockout-threshold"
30 v-model.number="form.lockoutThreshold"
31 type="number"
32 aria-describedby="lockout-threshold-help-block"
33 :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"
65 @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"
73 @input="$v.form.unlockMethod.$touch()"
74 >
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080075 {{ $t('pageLocalUserManagement.modal.automaticAfterTimeout') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080076 </b-form-radio>
77 <div class="mt-3 ml-4">
78 <b-form-text id="lockout-duration-help-block">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080079 {{
80 $t('pageLocalUserManagement.modal.timeoutDurationSeconds')
81 }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080082 </b-form-text>
83 <b-form-input
84 v-model.number="form.lockoutDuration"
85 aria-describedby="lockout-duration-help-block"
86 type="number"
87 :state="getValidationState($v.form.lockoutDuration)"
88 :readonly="$v.form.unlockMethod.$model === 0"
89 @input="$v.form.lockoutDuration.$touch()"
90 />
91 <b-form-invalid-feedback role="alert">
92 <template v-if="!$v.form.lockoutDuration.required">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080093 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080094 </template>
95 <template v-else-if="!$v.form.lockoutDuration.minvalue">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080096 {{ $t('global.form.mustBeAtLeast', { value: 1 }) }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080097 </template>
98 </b-form-invalid-feedback>
99 </div>
100 </b-form-group>
101 </b-col>
102 </b-row>
103 </b-container>
104 </b-form>
105 </b-modal>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800106</template>
107
108<script>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800109import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js';
110import {
111 required,
112 requiredIf,
113 minValue,
114 maxValue
115} from 'vuelidate/lib/validators';
116
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800117export default {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800118 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600119 props: {
120 settings: {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800121 type: Object,
122 required: true
Derick Montague09e45cd2020-01-23 15:45:57 -0600123 }
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800124 },
125 data() {
126 return {
127 form: {
128 lockoutThreshold: 0,
129 unlockMethod: 0,
130 lockoutDuration: null
131 }
132 };
133 },
134 watch: {
135 settings: function({ lockoutThreshold, lockoutDuration }) {
136 this.form.lockoutThreshold = lockoutThreshold;
137 this.form.unlockMethod = lockoutDuration ? 1 : 0;
138 this.form.lockoutDuration = lockoutDuration ? lockoutDuration : null;
139 }
140 },
141 validations: {
142 form: {
143 lockoutThreshold: {
144 minValue: minValue(0),
145 maxValue: maxValue(65535),
146 required
147 },
148 unlockMethod: { required },
149 lockoutDuration: {
150 minValue: function(value) {
151 return this.form.unlockMethod === 0 || value > 0;
152 },
153 required: requiredIf(function() {
154 return this.form.unlockMethod === 1;
155 })
156 }
157 }
158 },
159 methods: {
160 handleSubmit() {
161 this.$v.$touch();
162 if (this.$v.$invalid) return;
163
164 let lockoutThreshold;
165 let lockoutDuration;
166 if (this.$v.form.lockoutThreshold.$dirty) {
167 lockoutThreshold = this.form.lockoutThreshold;
168 }
169 if (this.$v.form.unlockMethod.$dirty) {
170 lockoutDuration = this.form.unlockMethod
171 ? this.form.lockoutDuration
172 : 0;
173 }
174
175 this.$emit('ok', { lockoutThreshold, lockoutDuration });
176 this.closeModal();
177 },
178 onOk(bvModalEvt) {
179 // prevent modal close
180 bvModalEvt.preventDefault();
181 this.handleSubmit();
182 },
183 closeModal() {
184 this.$nextTick(() => {
185 this.$refs.modal.hide();
186 });
187 },
188 resetForm() {
189 // Reset form models
190 this.form.lockoutThreshold = this.settings.lockoutThreshold;
191 this.form.unlockMethod = this.settings.lockoutDuration ? 1 : 0;
192 this.form.lockoutDuration = this.settings.lockoutDuration
193 ? this.settings.lockoutDuration
194 : null;
195 this.$v.$reset(); // clear validations
196 }
Derick Montague09e45cd2020-01-23 15:45:57 -0600197 }
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800198};
199</script>