Skip to content

Commit 2b88087

Browse files
authored
Merge pull request #8357 from nextcloud-libraries/backport/8350/stable8
[stable8] fix(NcPasswordField): reset validation on change
2 parents b0ba651 + 49f10b5 commit 2b88087

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/components/NcPasswordField/NcPasswordField.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ General purpose password field component.
1919
<NcPasswordField id="textField"
2020
v-model="text2"
2121
:label-outside="true"
22-
placeholder="Min. 12 characters" />
22+
placeholder="Min. 12 characters"
23+
:success="true"
24+
helper-text="Password is secure" />
2325
</div>
2426
<div class="external-label">
2527
<label for="textField2">New password</label>
@@ -32,10 +34,9 @@ General purpose password field component.
3234
</div>
3335

3436
<NcPasswordField v-model="text4"
35-
label="Good new password"
36-
:success="true"
37-
placeholder="Min. 12 characters"
38-
helper-text="Password is secure" />
37+
label="Validate new password"
38+
check-password-strength
39+
placeholder="Min. 12 characters" />
3940

4041
<NcPasswordField v-model="text5"
4142
:disabled="true"
@@ -51,7 +52,7 @@ export default {
5152
data() {
5253
return {
5354
text1: '',
54-
text2: '',
55+
text2: 'FWZxt29XEoTQfnBEa',
5556
text3: 'hunter',
5657
text4: '',
5758
text5: '',
@@ -324,10 +325,10 @@ export default {
324325
325326
watch: {
326327
model(newValue) {
327-
if (this.checkPasswordStrength) {
328-
if (passwordPolicy === null) {
329-
return
330-
}
328+
// Reset internal validation state on value change
329+
this.isValid = undefined
330+
this.internalHelpMessage = ''
331+
if (newValue && this.checkPasswordStrength) {
331332
this.checkPassword(newValue)
332333
}
333334
},

styleguide/global.requires.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const USER_GROUPS = [
3030
* @param {object} error Axios error
3131
*/
3232
function mockRequests(error) {
33-
const { request } = error
33+
const { request, config } = error
3434
let data = null
3535

3636
// Mock resolved link references for NcRichText
@@ -60,6 +60,22 @@ function mockRequests(error) {
6060
data = { groups: USER_GROUPS.filter((e) => !requestGroups[1] || e.displayname.startsWith(requestGroups[1]) || e.id.startsWith(requestGroups[1])) }
6161
}
6262

63+
const requestPasswordPolicy = request.responseURL.match(/apps\/password_policy\/api\/v1\/validate/)
64+
if (requestPasswordPolicy) {
65+
const payload = typeof config.data === 'string' ? JSON.parse(config.data) : config.data
66+
67+
if (payload.password.length < 12) {
68+
data = {
69+
passed: false,
70+
reason: 'Password needs to be at least 12 characters long',
71+
}
72+
} else {
73+
data = {
74+
passed: true,
75+
}
76+
}
77+
}
78+
6379
if (data) {
6480
return Promise.resolve({ data: { ocs: { data } } })
6581
}

0 commit comments

Comments
 (0)