From 5cd3e2fa2a89021fba4ae3b479f5f9ac4df6cfc3 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Fri, 20 Oct 2023 23:42:30 +0200 Subject: [PATCH] refactor(NcPasswordField): reuse password policy Signed-off-by: Grigorii K. Shartsev --- .../NcPasswordField/NcPasswordField.vue | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/NcPasswordField/NcPasswordField.vue b/src/components/NcPasswordField/NcPasswordField.vue index 86e594eba9..c11a5ccfce 100644 --- a/src/components/NcPasswordField/NcPasswordField.vue +++ b/src/components/NcPasswordField/NcPasswordField.vue @@ -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 { @@ -203,7 +218,6 @@ export default { return { isPasswordHidden: true, internalHelpMessage: '', - passwordPolicy: loadState('core', 'capabilities', {}).password_policy || null, isValid: null, } }, @@ -223,7 +237,7 @@ export default { }, rules() { - const { minlength, passwordPolicy } = this + const { minlength } = this return { minlength: minlength ?? passwordPolicy?.minLength, } @@ -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) } }, },