Skip to content

Commit 57ff372

Browse files
skjnldsvnextcloud-command
authored andcommitted
Fix loading indicator and better feedback with radio type switch
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent ff130e4 commit 57ff372

5 files changed

Lines changed: 85 additions & 79 deletions

js/password_policy-settings.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/password_policy-settings.js.LICENSE.txt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,7 @@
55
* @license MIT
66
*/
77

8-
/**
9-
* @copyright Copyright (c) 2019 Greta Doci <gretadoci@gmail.com>
10-
*
11-
* @author Greta Doci <gretadoci@gmail.com>
12-
*
13-
* @license GNU AGPL version 3 or any later version
14-
*
15-
* This program is free software: you can redistribute it and/or modify
16-
* it under the terms of the GNU Affero General Public License as
17-
* published by the Free Software Foundation, either version 3 of the
18-
* License, or (at your option) any later version.
19-
*
20-
* This program is distributed in the hope that it will be useful,
21-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23-
* GNU Affero General Public License for more details.
24-
*
25-
* You should have received a copy of the GNU Affero General Public License
26-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27-
*
28-
*/
8+
/*! For license information please see CheckboxRadioSwitch.js.LICENSE.txt */
299

3010
/**
3111
* @copyright Copyright (c) 2021 Jonas Rittershofer <jotoeri@users.noreply.github.com>

js/password_policy-settings.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 20 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AdminSettings.vue

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,48 @@
2323

2424
<template>
2525
<SettingsSection :title="t('password_policy', 'Password policy')">
26-
<div id="password-policy__saving-msg" class="msg success inlineblock" style="display: none;">
26+
<div id="password-policy__saving-msg" class="msg success inlineblock" style="display:none">
2727
{{ t('password_policy', 'Saved') }}
2828
</div>
2929

3030
<ul class="password-policy__settings-list">
3131
<li>
32-
<label>
33-
<input id="password-policy__settings__min-length"
34-
v-model="config.minLength"
35-
type="number"
36-
@change="updateNumberSetting('minLength')">
32+
<input id="password-policy__settings__min-length"
33+
v-model="config.minLength"
34+
min="0"
35+
type="number"
36+
@change="updateNumberSetting('minLength')">
37+
<label for="password-policy__settings__min-length">
3738
{{ t('password_policy', 'Minimum password length') }}
3839
</label>
3940
</li>
4041
<li>
41-
<label>
42-
<input id="password-policy-history-size"
43-
v-model="config.historySize"
44-
type="number"
45-
@change="updateNumberSetting('historySize')">
42+
<input id="password-policy-history-size"
43+
v-model="config.historySize"
44+
min="0"
45+
type="number"
46+
@change="updateNumberSetting('historySize')">
47+
<label for="password-policy-history-size">
4648
{{ t('password_policy', 'User password history') }}
4749
</label>
4850
</li>
4951
<li>
50-
<label>
51-
<input id="password-policy-expiration"
52-
v-model="config.expiration"
53-
type="number"
54-
@change="updateNumberSetting('expiration')">
52+
<input id="password-policy-expiration"
53+
v-model="config.expiration"
54+
min="0"
55+
type="number"
56+
@change="updateNumberSetting('expiration')">
57+
<label for="password-policy-expiration">
5558
{{ t('password_policy', 'Number of days until user password expires') }}
5659
</label>
5760
</li>
5861
<li>
59-
<label>
60-
<input id="password-policy_failed-login"
61-
v-model="config.maximumLoginAttempts"
62-
type="number"
63-
@change="updateNumberSetting('maximumLoginAttempts')">
62+
<input id="password-policy_failed-login"
63+
v-model="config.maximumLoginAttempts"
64+
min="0"
65+
type="number"
66+
@change="updateNumberSetting('maximumLoginAttempts')">
67+
<label for="password-policy_failed-login">
6468
{{ t('password_policy', 'Number of login attempts before the user account is blocked (0 for no limit)') }}
6569
</label>
6670
</li>
@@ -69,30 +73,35 @@
6973
<ul class="password-policy__settings-list">
7074
<li>
7175
<CheckboxRadioSwitch :checked.sync="config.enforceNonCommonPassword"
76+
type="switch"
7277
@update:checked="updateBoolSetting('enforceNonCommonPassword')">
7378
{{ t('password_policy', 'Forbid common passwords') }}
7479
</CheckboxRadioSwitch>
7580
</li>
7681
<li>
7782
<CheckboxRadioSwitch :checked.sync="config.enforceUpperLowerCase"
83+
type="switch"
7884
@update:checked="updateBoolSetting('enforceUpperLowerCase')">
7985
{{ t('password_policy', 'Enforce upper and lower case characters') }}
8086
</CheckboxRadioSwitch>
8187
</li>
8288
<li>
8389
<CheckboxRadioSwitch :checked.sync="config.enforceNumericCharacters"
90+
type="switch"
8491
@update:checked="updateBoolSetting('enforceNumericCharacters')">
8592
{{ t('password_policy', 'Enforce numeric characters') }}
8693
</CheckboxRadioSwitch>
8794
</li>
8895
<li>
8996
<CheckboxRadioSwitch :checked.sync="config.enforceSpecialCharacters"
97+
type="switch"
9098
@update:checked="updateBoolSetting('enforceSpecialCharacters')">
9199
{{ t('password_policy', 'Enforce special characters') }}
92100
</CheckboxRadioSwitch>
93101
</li>
94102
<li>
95103
<CheckboxRadioSwitch :checked.sync="config.enforceHaveIBeenPwned"
104+
type="switch"
96105
@update:checked="updateBoolSetting('enforceHaveIBeenPwned')">
97106
{{ t('password_policy', 'Check password against the list of breached passwords from haveibeenpwned.com') }}
98107
</CheckboxRadioSwitch>
@@ -123,12 +132,10 @@ export default {
123132
},
124133
125134
methods: {
126-
updateBoolSetting(setting) {
127-
OCP.AppConfig.setValue('password_policy', setting, this.config[setting] ? '1' : '0')
135+
async updateBoolSetting(setting) {
136+
await this.setValue(setting, this.config[setting] ? '1' : '0')
128137
},
129-
updateNumberSetting(setting) {
130-
OC.msg.startSaving('#password-policy__saving-msg')
131-
138+
async updateNumberSetting(setting) {
132139
// If value not only (positive) numbers
133140
if (!/^\d+$/.test(this.config[setting])) {
134141
let message = t('password_policy', 'Unknown error')
@@ -146,27 +153,42 @@ export default {
146153
message = t('password_policy', 'Maximum login attempts have to be a non negative number')
147154
break
148155
}
149-
OC.msg.finishedSaving('#password-policy__saving-msg',
150-
{
151-
status: 'failure',
152-
data: {
153-
message,
154-
},
155-
}
156-
)
156+
OC.msg.finishedSaving('#password-policy__saving-msg', {
157+
status: 'failure',
158+
data: {
159+
message,
160+
},
161+
})
157162
return
158163
}
159164
160165
// Otherwise store Value
161-
OCP.AppConfig.setValue('password_policy', setting, this.config[setting])
162-
OC.msg.finishedSaving('#password-policy__saving-msg',
163-
{
166+
await this.setValue(setting, this.config[setting])
167+
},
168+
169+
/**
170+
* Save the provided setting and value
171+
*
172+
* @param {string} setting the app config key
173+
* @param {string} value the app config value
174+
*/
175+
async setValue(setting, value) {
176+
OC.msg.startSaving('#password-policy__saving-msg')
177+
178+
OCP.AppConfig.setValue('password_policy', setting, value, {
179+
success: () => OC.msg.finishedSaving('#password-policy__saving-msg', {
164180
status: 'success',
165181
data: {
166182
message: t('password_policy', 'Saved'),
167183
},
168-
}
169-
)
184+
}),
185+
error: () => OC.msg.finishedSaving('#password-policy__saving-msg', {
186+
status: 'failure',
187+
data: {
188+
message: t('password_policy', 'Error while saving'),
189+
},
190+
}),
191+
})
170192
},
171193
},
172194
}

0 commit comments

Comments
 (0)