UNPKG

@nextcloud/vue

Version:
60 lines (59 loc) 3.33 kB
import r from "vue-material-design-icons/Eye.vue"; import a from "vue-material-design-icons/EyeOff.vue"; import i from "./NcInputField.mjs"; import o from "debounce"; import n from "@nextcloud/axios"; import { loadState as l } from "@nextcloud/initial-state"; import { generateOcsUrl as d } from "@nextcloud/router"; import { t as s } from "../chunks/l10n-9a5a6afc.mjs"; import { l as p } from "../chunks/logger-ccc7ee65.mjs"; import { n as u } from "../chunks/_plugin-vue2_normalizer-5b4c43a4.mjs"; const c = { name: "NcPasswordField", components: { NcInputField: i, Eye: r, EyeOff: a }, inheritAttrs: !1, props: { ...i.props, helperText: { type: String, default: "" }, checkPasswordStrength: { type: Boolean, default: !1 }, minlength: { type: Number, default: 0 }, maxlength: { type: Number, default: null }, showTrailingButton: { type: Boolean, default: !0 } }, emits: ["valid", "invalid", "update:value"], data() { return { isPasswordHidden: !0, internalHelpMessage: "", passwordPolicy: l("core", "capabilities", {}).password_policy || null, isValid: null }; }, computed: { computedError() { return this.error || this.isValid === !1; }, computedSuccess() { return this.success || this.isValid === !0; }, computedHelperText() { return this.helperText.length > 0 ? this.helperText : this.internalHelpMessage; }, rules() { const { minlength: t, passwordPolicy: e } = this; return { minlength: t != null ? t : e == null ? void 0 : e.minLength }; }, trailingButtonLabelPassword() { return this.isPasswordHidden ? s("Show password") : s("Hide password"); } }, watch: { value(t) { if (this.checkPasswordStrength) { if (this.passwordPolicy === null) return; this.passwordPolicy && this.checkPassword(t); } } }, methods: { focus() { this.$refs.inputField.focus(); }, select() { this.$refs.inputField.select(); }, handleInput(t) { this.$emit("update:value", t.target.value); }, togglePasswordVisibility() { this.isPasswordHidden = !this.isPasswordHidden; }, checkPassword: o(async function(t) { try { const { data: e } = await n.post(d("apps/password_policy/api/v1/validate"), { password: t }); if (this.isValid = e.ocs.data.passed, e.ocs.data.passed) { this.internalHelpMessage = s("Password is secure"), this.$emit("valid"); return; } this.internalHelpMessage = e.ocs.data.reason, this.$emit("invalid"); } catch (e) { p.error("Password policy returned an error", e); } }, 500) } }; var h = function() { var t = this, e = t._self._c; return e("NcInputField", t._g(t._b({ ref: "inputField", attrs: { type: t.isPasswordHidden ? "password" : "text", "show-trailing-button": t.showTrailingButton && !0, "trailing-button-label": t.trailingButtonLabelPassword, "helper-text": t.computedHelperText, error: t.computedError, success: t.computedSuccess, minlength: t.rules.minlength }, on: { "trailing-button-click": t.togglePasswordVisibility, input: t.handleInput }, scopedSlots: t._u([{ key: "trailing-button-icon", fn: function() { return [t.isPasswordHidden ? e("Eye", { attrs: { size: 18 } }) : e("EyeOff", { attrs: { size: 18 } })]; }, proxy: !0 }]) }, "NcInputField", { ...t.$attrs, ...t.$props }, !1), t.$listeners), [t._t("default")], 2); }, m = [], f = u(c, h, m, !1, null, null, null, null); const $ = f.exports; export { $ as default };