security-CIGqzmF3.mjs 12.9 KB
import { _ as _sfc_main$1 } from './PageCard-BPh5vXzv.mjs';
import { _ as _sfc_main$2 } from './Form-9sZcpyMB.mjs';
import { _ as _sfc_main$3 } from './FormField-CaARTmzs.mjs';
import { _ as _sfc_main$4 } from './Input-QBf9hfFU.mjs';
import { u as useAppI18n, a as useToast, _ as _sfc_main$9 } from './server.mjs';
import { defineComponent, ref, computed, reactive, unref, withCtx, createVNode, useSSRContext } from 'vue';
import { ssrRenderComponent } from 'vue/server-renderer';
import * as z from 'zod';
import { u as useSettingsApi } from './useSettingsApi-D7_a-esD.mjs';
import '../nitro/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '@iconify/utils';
import 'consola';
import 'perfect-debounce';
import 'tailwindcss/colors';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/plugins';
import 'unhead/utils';

const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "security",
  __ssrInlineRender: true,
  setup(__props) {
    const { t } = useAppI18n();
    const toast = useToast();
    const isPasswordSubmitting = ref(false);
    const isDeleteSubmitting = ref(false);
    const settingsApi = useSettingsApi();
    const buildPasswordSchema = () => z.object({
      current: z.string().min(8, t("settings.security.password.validation.minLength")),
      new: z.string().min(8, t("settings.security.password.validation.minLength"))
    });
    const passwordSchema = computed(buildPasswordSchema);
    const password = reactive({
      current: "",
      new: ""
    });
    const validate = (state) => {
      const errors = [];
      if (state.current && state.new && state.current === state.new) {
        errors.push({ name: "new", message: t("settings.security.password.validation.different") });
      }
      return errors;
    };
    async function onPasswordSubmit(event) {
      isPasswordSubmitting.value = true;
      try {
        const result = await settingsApi.updatePassword(event.data);
        if (!result.success) {
          toast.add({
            title: t("common.error"),
            description: result.message,
            icon: "i-lucide-circle-alert",
            color: "error"
          });
          return;
        }
        password.current = "";
        password.new = "";
        toast.add({
          title: t("settings.profile.toastTitle"),
          description: result.message,
          icon: "i-lucide-check",
          color: "success"
        });
      } catch {
        toast.add({
          title: t("common.error"),
          description: t("common.requestFailed"),
          icon: "i-lucide-circle-alert",
          color: "error"
        });
      } finally {
        isPasswordSubmitting.value = false;
      }
    }
    async function onDeleteAccount() {
      isDeleteSubmitting.value = true;
      try {
        const result = await settingsApi.deleteAccount();
        if (!result.success) {
          toast.add({
            title: t("common.error"),
            description: result.message,
            icon: "i-lucide-circle-alert",
            color: "error"
          });
          return;
        }
        toast.add({
          title: t("settings.profile.toastTitle"),
          description: result.message,
          icon: "i-lucide-check",
          color: "success"
        });
      } catch {
        toast.add({
          title: t("common.error"),
          description: t("common.requestFailed"),
          icon: "i-lucide-circle-alert",
          color: "error"
        });
      } finally {
        isDeleteSubmitting.value = false;
      }
    }
    return (_ctx, _push, _parent, _attrs) => {
      const _component_UPageCard = _sfc_main$1;
      const _component_UForm = _sfc_main$2;
      const _component_UFormField = _sfc_main$3;
      const _component_UInput = _sfc_main$4;
      const _component_UButton = _sfc_main$9;
      _push(`<!--[-->`);
      _push(ssrRenderComponent(_component_UPageCard, {
        title: unref(t)("settings.security.password.title"),
        description: unref(t)("settings.security.password.description"),
        variant: "subtle"
      }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(ssrRenderComponent(_component_UForm, {
              schema: unref(passwordSchema),
              state: unref(password),
              validate,
              class: "flex flex-col gap-4 max-w-xs",
              onSubmit: onPasswordSubmit
            }, {
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(ssrRenderComponent(_component_UFormField, { name: "current" }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(ssrRenderComponent(_component_UInput, {
                          modelValue: unref(password).current,
                          "onUpdate:modelValue": ($event) => unref(password).current = $event,
                          type: "password",
                          placeholder: unref(t)("settings.security.password.currentPlaceholder"),
                          class: "w-full"
                        }, null, _parent4, _scopeId3));
                      } else {
                        return [
                          createVNode(_component_UInput, {
                            modelValue: unref(password).current,
                            "onUpdate:modelValue": ($event) => unref(password).current = $event,
                            type: "password",
                            placeholder: unref(t)("settings.security.password.currentPlaceholder"),
                            class: "w-full"
                          }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"])
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  _push3(ssrRenderComponent(_component_UFormField, { name: "new" }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(ssrRenderComponent(_component_UInput, {
                          modelValue: unref(password).new,
                          "onUpdate:modelValue": ($event) => unref(password).new = $event,
                          type: "password",
                          placeholder: unref(t)("settings.security.password.newPlaceholder"),
                          class: "w-full"
                        }, null, _parent4, _scopeId3));
                      } else {
                        return [
                          createVNode(_component_UInput, {
                            modelValue: unref(password).new,
                            "onUpdate:modelValue": ($event) => unref(password).new = $event,
                            type: "password",
                            placeholder: unref(t)("settings.security.password.newPlaceholder"),
                            class: "w-full"
                          }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"])
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  _push3(ssrRenderComponent(_component_UButton, {
                    label: unref(t)("settings.security.password.update"),
                    class: "w-fit",
                    type: "submit",
                    loading: unref(isPasswordSubmitting)
                  }, null, _parent3, _scopeId2));
                } else {
                  return [
                    createVNode(_component_UFormField, { name: "current" }, {
                      default: withCtx(() => [
                        createVNode(_component_UInput, {
                          modelValue: unref(password).current,
                          "onUpdate:modelValue": ($event) => unref(password).current = $event,
                          type: "password",
                          placeholder: unref(t)("settings.security.password.currentPlaceholder"),
                          class: "w-full"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_UFormField, { name: "new" }, {
                      default: withCtx(() => [
                        createVNode(_component_UInput, {
                          modelValue: unref(password).new,
                          "onUpdate:modelValue": ($event) => unref(password).new = $event,
                          type: "password",
                          placeholder: unref(t)("settings.security.password.newPlaceholder"),
                          class: "w-full"
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"])
                      ]),
                      _: 1
                    }),
                    createVNode(_component_UButton, {
                      label: unref(t)("settings.security.password.update"),
                      class: "w-fit",
                      type: "submit",
                      loading: unref(isPasswordSubmitting)
                    }, null, 8, ["label", "loading"])
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
          } else {
            return [
              createVNode(_component_UForm, {
                schema: unref(passwordSchema),
                state: unref(password),
                validate,
                class: "flex flex-col gap-4 max-w-xs",
                onSubmit: onPasswordSubmit
              }, {
                default: withCtx(() => [
                  createVNode(_component_UFormField, { name: "current" }, {
                    default: withCtx(() => [
                      createVNode(_component_UInput, {
                        modelValue: unref(password).current,
                        "onUpdate:modelValue": ($event) => unref(password).current = $event,
                        type: "password",
                        placeholder: unref(t)("settings.security.password.currentPlaceholder"),
                        class: "w-full"
                      }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"])
                    ]),
                    _: 1
                  }),
                  createVNode(_component_UFormField, { name: "new" }, {
                    default: withCtx(() => [
                      createVNode(_component_UInput, {
                        modelValue: unref(password).new,
                        "onUpdate:modelValue": ($event) => unref(password).new = $event,
                        type: "password",
                        placeholder: unref(t)("settings.security.password.newPlaceholder"),
                        class: "w-full"
                      }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder"])
                    ]),
                    _: 1
                  }),
                  createVNode(_component_UButton, {
                    label: unref(t)("settings.security.password.update"),
                    class: "w-fit",
                    type: "submit",
                    loading: unref(isPasswordSubmitting)
                  }, null, 8, ["label", "loading"])
                ]),
                _: 1
              }, 8, ["schema", "state"])
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(ssrRenderComponent(_component_UPageCard, {
        title: unref(t)("settings.security.account.title"),
        description: unref(t)("settings.security.account.description"),
        class: "bg-linear-to-tl from-error/10 from-5% to-default"
      }, {
        footer: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(ssrRenderComponent(_component_UButton, {
              label: unref(t)("settings.security.account.delete"),
              color: "error",
              loading: unref(isDeleteSubmitting),
              onClick: onDeleteAccount
            }, null, _parent2, _scopeId));
          } else {
            return [
              createVNode(_component_UButton, {
                label: unref(t)("settings.security.account.delete"),
                color: "error",
                loading: unref(isDeleteSubmitting),
                onClick: onDeleteAccount
              }, null, 8, ["label", "loading"])
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`<!--]-->`);
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/settings/security.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};

export { _sfc_main as default };
//# sourceMappingURL=security-CIGqzmF3.mjs.map