n8n-editor-ui
Version:
Workflow Editor UI for n8n
136 lines (135 loc) • 5.02 kB
JavaScript
import { E as createCommentVNode, It as ref, P as defineComponent, T as createBlock, Z as onMounted, et as openBlock } from "./vue.runtime.esm-bundler-tP5dCd7J.js";
import { gt as useI18n } from "./_MapCache-B159LOu5.js";
import "./src-BW7zuOU1.js";
import "./en-b3uD8cvU.js";
import "./preload-helper-CR0ecmWK.js";
import "./_plugin-vue_export-helper-BwBpWJRZ.js";
import { y as useRouter } from "./truncate-Dc5upPom.js";
import "./icon-MZ_3fB_h.js";
import "./empty-4-N75rxI.js";
import { nr as useUsersStore } from "./useTelemetry-C797TaYa.js";
import { t as useToast } from "./useToast-ZaUhbG9w.js";
import "./sanitize-html-CgpOSgtK.js";
import "./CalendarDate-DxkU3CHY.js";
import "./path-browserify-B5h_dP_u.js";
import { Io as VIEWS, Tc as MFA_AUTHENTICATION_CODE_INPUT_MAX_LENGTH } from "./constants-CX1ozgFz.js";
import "./merge-BArJwbQo.js";
import "./_baseOrderBy-DL6Sy5xK.js";
import "./dateformat-CMLc6OKJ.js";
import "./useDebounce-RgPaX171.js";
import "./useExternalHooks-CYMS6JpD.js";
import "./useStyles-DhM0cpS7.js";
import "./sso.store-B_c2j1dV.js";
import { t as AuthView_default } from "./AuthView-DDyHoJhx.js";
var ChangePasswordView_default = /* @__PURE__ */ defineComponent({
__name: "ChangePasswordView",
setup(__props) {
const usersStore = useUsersStore();
const locale = useI18n();
const toast = useToast();
const router = useRouter();
const password = ref("");
const loading = ref(false);
const config = ref(null);
const passwordsMatch = (value) => {
if (typeof value !== "string") return false;
if (value !== password.value) return { messageKey: "auth.changePassword.passwordsMustMatchError" };
return false;
};
const getResetToken = () => {
return !router.currentRoute.value.query.token || typeof router.currentRoute.value.query.token !== "string" ? null : router.currentRoute.value.query.token;
};
const getMfaEnabled = () => {
if (!router.currentRoute.value.query.mfaEnabled) return null;
return router.currentRoute.value.query.mfaEnabled === "true" ? true : false;
};
const onSubmit = async (values) => {
try {
loading.value = true;
const token = getResetToken();
if (token) {
const changePasswordParameters = {
token,
password: password.value,
...values.mfaCode && { mfaCode: values.mfaCode }
};
await usersStore.changePassword(changePasswordParameters);
toast.showMessage({
type: "success",
title: locale.baseText("auth.changePassword.passwordUpdated"),
message: locale.baseText("auth.changePassword.passwordUpdatedMessage")
});
await router.push({ name: VIEWS.SIGNIN });
} else toast.showError(new Error(locale.baseText("auth.validation.missingParameters")), locale.baseText("auth.changePassword.error"));
} catch (error) {
toast.showError(error, locale.baseText("auth.changePassword.error"));
}
loading.value = false;
};
const onInput = (e) => {
if (e.name === "password" && typeof e.value === "string") password.value = e.value;
};
onMounted(async () => {
const form = {
title: locale.baseText("auth.changePassword"),
buttonText: locale.baseText("auth.changePassword"),
redirectText: locale.baseText("auth.signin"),
redirectLink: "/signin",
inputs: [{
name: "password",
properties: {
label: locale.baseText("auth.newPassword"),
type: "password",
required: true,
validationRules: [{ name: "DEFAULT_PASSWORD_RULES" }],
infoText: locale.baseText("auth.defaultPasswordRequirements"),
autocomplete: "new-password",
capitalize: true
}
}, {
name: "password2",
properties: {
label: locale.baseText("auth.changePassword.reenterNewPassword"),
type: "password",
required: true,
validators: { TWO_PASSWORDS_MATCH: { validate: passwordsMatch } },
validationRules: [{ name: "TWO_PASSWORDS_MATCH" }],
autocomplete: "new-password",
capitalize: true
}
}]
};
const token = getResetToken();
if (getMfaEnabled()) form.inputs.push({
name: "mfaCode",
initialValue: "",
properties: {
required: true,
label: locale.baseText("mfa.code.input.label"),
placeholder: locale.baseText("mfa.code.input.placeholder"),
maxlength: 6,
capitalize: true,
validateOnBlur: true
}
});
config.value = form;
try {
if (!token) throw new Error(locale.baseText("auth.changePassword.missingTokenError"));
await usersStore.validatePasswordToken({ token });
} catch (e) {
toast.showError(e, locale.baseText("auth.changePassword.tokenValidationError"));
router.replace({ name: VIEWS.SIGNIN });
}
});
return (_ctx, _cache) => {
return config.value ? (openBlock(), createBlock(AuthView_default, {
key: 0,
form: config.value,
"form-loading": loading.value,
onSubmit,
onUpdate: onInput
}, null, 8, ["form", "form-loading"])) : createCommentVNode("", true);
};
}
});
export { ChangePasswordView_default as default };