- Fix mustChangePassword session flag for users with pw=NULL - Add PrF (Private Führung) as new ArtFuehrung type - Split datetime-local into separate date + TimePicker5 (5-min steps, auto-repeat) - Responsive Beginn/Ende layout: stacked on mobile, inline on desktop - Sort BEOs alphabetically by Kürzel in selector - Title shows active kuppel; hide user display in header - Selected BEOs show Kürzel only (name stays in dropdown) - Session timeout reduced to 1 hour - Add CLAUDE.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 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,
|
|
});
|
|
|
|
if (mustChange) {
|
|
redirect('/change-password');
|
|
}
|
|
|
|
redirect('/');
|
|
}
|