import {
    generateOTPQRCode
} from "../../../../lib/otp.mjs";

export const get = async function (request, response) {
    if (request.getAuthState() != 'authenticated') {
        response.set('HX-Redirect', '/login').status(401).end();
        return;
    }

    let dbUser = await request.getUser();

    response.render(`views/htmx/profile/showMFA.njk`, {
        user: {
            firstName: dbUser.givenname,
            lastName: dbUser.sn,
            mail: dbUser.mail,
        },
        data: {
            otpsecret: dbUser.otpsecret,
            yubikey: dbUser.yubikey,
            qrcode: await generateOTPQRCode(dbUser.mail, dbUser.otpsecret)
        }
    });
}

export const post = async function (request, response) {
    console.log(request.body);
    response.redirect("/login");
}
