add user accounts and OSM peak catalog with zoom-based notability

This commit is contained in:
Vincent van der Wal
2026-07-22 11:10:59 +02:00
parent 196f30521c
commit b17f56b194
26 changed files with 1019 additions and 191 deletions
+33
View File
@@ -0,0 +1,33 @@
import { fail, redirect } from '@sveltejs/kit';
import { createSession, createUser, findUser } from '$lib/server/auth';
import type { Actions } from './$types';
export const actions: Actions = {
default: async ({ request, cookies }) => {
const form = await request.formData();
const username = String(form.get('username') ?? '').trim();
const password = String(form.get('password') ?? '');
if (!/^[a-zA-Z0-9_.-]{3,30}$/.test(username)) {
return fail(400, {
username,
error: 'Username must be 3-30 characters (letters, digits, _ . -).'
});
}
if (password.length < 8) {
return fail(400, { username, error: 'Password must be at least 8 characters.' });
}
if (findUser(username)) {
return fail(400, { username, error: 'That username is taken.' });
}
const user = createUser(username, password);
cookies.set('session', createSession(user.id), {
path: '/',
httpOnly: true,
sameSite: 'lax',
maxAge: 30 * 86400
});
redirect(303, '/');
}
};