1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import { fd, get, register } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
export const load = async ({ parent }) => {
const { user } = await parent();
if (user) redirect(307, `/${user.username}`);
const index = Math.floor(Math.random() * 64) + 1;
const { challenge } = await get("/challenge");
return { index, challenge };
};
export const actions = {
default: async ({ cookies, request }) => {
const ip = request.headers.get("cf-connecting-ip");
const host = request.headers.get("host");
const form = await fd(request);
const { picture, username, password, challenge, recaptcha } = form;
let { loginRedirect } = form;
if (loginRedirect === "undefined") loginRedirect = undefined;
const user = { picture, username, password, challenge, recaptcha };
return register(user, ip, cookies, loginRedirect, host);
},
};
|