import { y as defineEventHandler, b0 as useLogger, aE as readBody, U as User, v as createError, K as enqueueMail, aC as publicSettings } from '../../../nitro/nitro.mjs';
import 'luxon';
import '@sequelize/core';
import 'html-to-text';
import 'zod';
import 'crypto';
import 'node:fs';
import 'sharp';
import 'path';
import 'node:stream';
import 'jsdom';
import 'dompurify';
import 'mime-types';
import 'fs';
import 'fs/promises';
import 'linkify-html';
import '@peertube/http-signature';
import 'jsonld';
import 'lodash.intersection';
import 'email-templates';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'node:events';
import 'node:buffer';
import 'node:path';
import 'vue';
import 'vue-router';
import 'dotenv';
import 'url';
import 'bcryptjs';
import 'slugify';
import 'umzug';
import 'consola';
import '@sequelize/core/decorators-legacy';
import 'util';
import 'mitt';
import 'ical.js';
import 'node:url';
import 'fast-xml-parser';

const recover_post = defineEventHandler(async (event) => {
  const log = useLogger("user/recover");
  const { email } = await readBody(event);
  const user = await User.findOne({ where: { email, is_active: true } });
  if (!user) {
    log.warn("User not found", email);
    throw createError({ statusCode: 404, statusMessage: "User not found" });
  }
  await user.generateRecoverCode();
  enqueueMail(user.email, "recover", { user, config: publicSettings }, event.context.locale);
});

export { recover_post as default };
