Skip to content

Commit

Permalink
refactor(NcPasswordField): reuse password policy
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme committed Oct 20, 2023
1 parent 3d5b969 commit 5cd3e2f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/NcPasswordField/NcPasswordField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ import { generateOcsUrl } from '@nextcloud/router'
import { t } from '../../l10n.js'
import logger from '../../utils/logger.js'
/**
* @typedef PasswordPolicy
* @property {object} api - The URLs to the password_policy app methods
* @property {string} api.generate - The URL to the password generator
* @property {string} api.validate - The URL to the password validator
* @property {boolean} enforceNonCommonPassword - Whether to enforce non common passwords
* @property {boolean} enforceNumericCharacters - Whether to enforce numeric characters
* @property {boolean} enforceSpecialCharacters - Whether to enforce special characters
* @property {boolean} enforceUpperLowerCase - Whether to enforce upper and lower case
* @property {number} minLength - The minimum length of the password
*/
/** @type {PasswordPolicy|null} */
const passwordPolicy = loadState('core', 'capabilities', {}).password_policy || null
const NcInputFieldProps = new Set(Object.keys(NcInputField.props))
export default {
Expand Down Expand Up @@ -203,7 +218,6 @@ export default {
return {
isPasswordHidden: true,
internalHelpMessage: '',
passwordPolicy: loadState('core', 'capabilities', {}).password_policy || null,
isValid: null,
}
},
Expand All @@ -223,7 +237,7 @@ export default {
},
rules() {
const { minlength, passwordPolicy } = this
const { minlength } = this
return {
minlength: minlength ?? passwordPolicy?.minLength,
}
Expand All @@ -248,12 +262,10 @@ export default {
watch: {
value(newValue) {
if (this.checkPasswordStrength) {
if (this.passwordPolicy === null) {
if (passwordPolicy === null) {
return
}
if (this.passwordPolicy) {
this.checkPassword(newValue)
}
this.checkPassword(newValue)
}
},
},
Expand Down

0 comments on commit 5cd3e2f

Please sign in to comment.