3fc5c9ff7a
- Datenbank auf utf8mb4_unicode_ci migriert (migrate_to_utf8mb4.sh) - beos: Spalte 'role' (kommagetrennte Rollen: guide, admin, key, deleted) - BEO-Auswahl im Formular filtert nur noch role='guide' - logbuch_objekte: ObjektName-Spalte entfernt, stattdessen JOIN auf objekte - lib/db.ts: charset utf8mb4 in Connection-Pool - Session und Auth um role-Feld erweitert - compose.yml: phpMyAdmin mit Traefik unter /myadmin - compose.yml: MySQL auf 127.0.0.1:3336 für SSH-Tunnel (lokale Entwicklung) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
'use server';
|
|
|
|
import { redirect } from 'next/navigation';
|
|
import { verifyCredentials, getBeoDisplayName } from '@/lib/auth';
|
|
import { createSession } from '@/lib/session';
|
|
|
|
export async function login(
|
|
_prevState: { error: string } | undefined,
|
|
formData: FormData
|
|
): Promise<{ error: string }> {
|
|
const kuerzel = (formData.get('username') as string)?.trim();
|
|
const password = formData.get('password') as string;
|
|
|
|
if (!kuerzel || !password) {
|
|
return { error: 'Bitte Kürzel und Passwort eingeben.' };
|
|
}
|
|
|
|
const result = await verifyCredentials(kuerzel, password);
|
|
|
|
if (!result || !result.valid) {
|
|
return { error: 'Ungültiges Kürzel oder Passwort.' };
|
|
}
|
|
|
|
const mustChange = result.beo.MustChangePassword === 1 || !result.beo.pw;
|
|
|
|
await createSession({
|
|
kuerzel: result.beo.kürzel ?? kuerzel,
|
|
beoId: result.beo.id,
|
|
beoName: getBeoDisplayName(result.beo),
|
|
mustChangePassword: mustChange,
|
|
isAuthenticated: true,
|
|
role: result.beo.role ?? null,
|
|
});
|
|
|
|
if (mustChange) {
|
|
redirect('/change-password');
|
|
}
|
|
|
|
redirect('/');
|
|
}
|