@octavianlab/olab-ui
Version:
Octavianlab UX/UI components
127 lines (126 loc) • 5.13 kB
JavaScript
import { resolveComponent as m, openBlock as a, createBlock as w, withCtx as u, createElementVNode as r, normalizeClass as h, toDisplayString as l, createElementBlock as i, createCommentVNode as p, Fragment as y, renderList as _, createTextVNode as k, pushScopeId as C, popScopeId as b } from "vue";
import { _ as v } from "./obannerbrowsersupport-8a97766f.js";
const x = {
name: "OPassword",
data() {
return {
value: "",
passwordContain: [],
filteredArray: [],
listCheckPassword: [
{
label: this.$translate("admin.generic.check.password.lowercase"),
condition: "lowercase"
},
{
label: this.$translate("admin.generic.check.password.uppercase"),
condition: "uppercase"
},
{
label: this.$translate("admin.generic.check.password.symbol"),
condition: "symbol"
},
{
label: this.$translate("admin.generic.check.password.number"),
condition: "number"
}
]
};
},
props: {
level: {
type: Number,
default: 4
},
type: {
type: String,
default: "old"
},
componentClass: { type: String, default: () => "w-100" },
placeholder: String,
configKey: { type: String, default: () => null }
},
watch: {
value(e) {
let o = /[a-z]+/, s = /[A-Z]+/, d = /[0-9]+/;
this.passwordContain = [], this.filteredArray = [];
for (let t of e.trim())
t ? (o.test(t) && this.passwordContain.push("lowercase"), s.test(t) && this.passwordContain.push("uppercase"), d.test(t) && this.passwordContain.push("number"), !o.test(t) && !s.test(t) && !d.test(t) && this.passwordContain.push("symbol"), this.filteredArray = [...new Set(this.passwordContain)]) : this.passwordContain = [];
this.checkPassword(), this.$emit("update:modelValue", e);
},
clearInput(e) {
e === !0 && (this.value = "");
}
},
methods: {
getConfig(e) {
return this.configKey === "player" ? this.$store.getters.configByKey(`password.policy.${this.configKey}.min.${e}`) : this.$store.getters.getConfigByKey(`password.policy.${this.configKey}.min.${e}`);
},
levelToCheck() {
return !this.configKey || !this.getConfig("groups") ? this.level : +this.getConfig("groups");
},
lengthToCheck() {
return !this.configKey || !this.getConfig("length") ? 8 : +this.getConfig("length");
},
handlePlaceholder() {
return !this.placeholder === void 0 ? this.$translate(`admin.generic.enter.${this.type}.password`) : this.placeholder;
},
passwordValidityIcon(e) {
return this.filteredArray.includes(e) ? "fad fa-circle-check p-mr-1 fa-lg text-success" : "fad fa-circle-xmark p-mr-1 fa-lg text-danger";
},
// Check su true manda emit che deve abilitare il button.
checkPassword() {
this.value.length >= this.lengthToCheck() && this.filteredArray.length === this.levelToCheck() ? this.$emit("check", !0) : this.$emit("check", !1);
}
}
}, g = (e) => (C("data-v-19a0e111"), e = e(), b(), e), P = { class: "p-d-flex p-jc-between" }, $ = { key: 0 }, S = { key: 0 }, V = /* @__PURE__ */ g(() => /* @__PURE__ */ r("hr", null, null, -1)), A = { class: "mt-2 p-text-bold" }, K = { key: 1 }, I = /* @__PURE__ */ g(() => /* @__PURE__ */ r("hr", null, null, -1)), T = { class: "p-text-bold" };
function B(e, o, s, d, t, c) {
const f = m("Password");
return a(), w(f, {
id: "o-password",
inputClass: "w-100",
modelValue: t.value,
"onUpdate:modelValue": o[0] || (o[0] = (n) => t.value = n),
placeholder: c.handlePlaceholder(),
toggleMask: t.value.length > 0,
feedback: s.type !== "old"
}, {
header: u(() => [
r("div", P, [
r("p", {
class: h(["p-text-bold", { "p-mb-3": s.type !== "new" }])
}, l(e.$translate(`admin.generic.${s.type}.password`)), 3),
s.type === "new" ? (a(), i("div", $, l(`${t.filteredArray.length} / ${c.levelToCheck()}`), 1)) : p("", !0)
])
]),
footer: u(() => [
s.type === "new" ? (a(), i("div", S, [
V,
r("p", A, l(e.$translate("admin.generic.check.password.rules")), 1),
r("p", null, l(e.$translate("admin.generic.check.password.length")) + ": " + l(c.lengthToCheck()), 1),
(a(!0), i(y, null, _(t.listCheckPassword, (n) => (a(), i("ul", {
class: "p-pl-2 p-ml-2 p-mt-0",
key: n
}, [
r("li", {
class: h(t.filteredArray.includes(n.condition) && "text-success p-text-bold")
}, [
r("i", {
class: h(c.passwordValidityIcon(n.condition))
}, null, 2),
k(" " + l(n.label), 1)
], 2)
]))), 128))
])) : p("", !0),
s.type === "confirm" ? (a(), i("div", K, [
I,
r("label", T, l(e.$translate("admin.generic.check.password.compare")), 1)
])) : p("", !0)
]),
_: 1
}, 8, ["modelValue", "placeholder", "toggleMask", "feedback"]);
}
const z = /* @__PURE__ */ v(x, [["render", B], ["__scopeId", "data-v-19a0e111"]]);
export {
z as O
};