01a7ac8e0b
Web-App zur Erfassung der Arbeitszeit, Layout/Architektur an Projekt logbuch angelehnt, mit grüner Grundfarbe und SQLite3 statt MySQL. - Eingabemaske: Datum (mit Wochentag), Ort (Kunde FFM/Homeoffice/Andrena), Beginn/Ende, Reisezeit, Vertriebsunterstützung (default 2h), Kommentar (max 500) - Berechnung: Arbeitszeit = Ende-Beginn; Mehrarbeit = Arbeitszeit - 8h - Pause - Pause als globale Einstellung (Einstellungen-Tab) - Tabs Eingabe/Liste/Einstellungen, letzte 10 Einträge unter der Maske - Single-User-Login (Benutzer Birgit + Passwort fest in .env), JWT-Cookie via jose - better-sqlite3, Docker-Setup für docker.citysensor.de Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
'use server';
|
|
|
|
import { headers } from 'next/headers';
|
|
import { redirect } from 'next/navigation';
|
|
import { verifyCredentials, getConfiguredUsername } from '@/lib/auth';
|
|
import { createSession } from '@/lib/session';
|
|
import { checkRateLimit } from '@/lib/ratelimit';
|
|
|
|
export async function login(
|
|
_prevState: { error: string } | undefined,
|
|
formData: FormData
|
|
): Promise<{ error: string }> {
|
|
const headersList = await headers();
|
|
const ip =
|
|
headersList.get('x-forwarded-for')?.split(',')[0].trim() ??
|
|
headersList.get('x-real-ip') ??
|
|
'unknown';
|
|
|
|
const { allowed, remainingMs } = checkRateLimit(ip);
|
|
if (!allowed) {
|
|
const minutes = Math.ceil(remainingMs / 60000);
|
|
return { error: `Zu viele Anmeldeversuche. Bitte ${minutes} Minute${minutes !== 1 ? 'n' : ''} warten.` };
|
|
}
|
|
|
|
const username = (formData.get('username') as string)?.trim();
|
|
const password = formData.get('password') as string;
|
|
|
|
if (!username || !password) {
|
|
return { error: 'Bitte Benutzer und Passwort eingeben.' };
|
|
}
|
|
|
|
if (!verifyCredentials(username, password)) {
|
|
return { error: 'Ungültiger Benutzer oder Passwort.' };
|
|
}
|
|
|
|
await createSession({
|
|
username: getConfiguredUsername(),
|
|
isAuthenticated: true,
|
|
});
|
|
|
|
redirect('/');
|
|
}
|