Files
logbuch/app/change-password/actions.ts
T
admin a75303f857 feat: Version 1.10.0 — DB-Zugriff auf PHP-Bridge (DB4js_all.php) umgestellt
- lib/db.ts entfernt, mysql2-Abhängigkeit gestrichen
- lib/phpdb.ts: HTTP-Client für alle DB-Operationen via DB4js_all.php
- Alle API-Routen und Server Actions auf phpdb.ts umgestellt
- compose.yml / docker-compose.prod.yml: MySQL/phpMyAdmin-Container entfernt
- app/api/DB4js_all.php/route.ts: Proxy für Statistik-AJAX-Calls
- Statistik-Grafik liest ab 2026 live aus logbuch statt StatistikJahre
- PHP 7.3-Kompatibilität: str_contains → strpos

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 08:48:15 +02:00

44 lines
1.3 KiB
TypeScript

'use server';
import { redirect } from 'next/navigation';
import { getSession, createSession } from '@/lib/session';
import { hashPassword } from '@/lib/auth';
import { updateBeoPassword } from '@/lib/phpdb';
export async function changePassword(
_prevState: { error: string } | undefined,
formData: FormData
): Promise<{ error: string }> {
const session = await getSession();
if (!session) redirect('/login');
const newPassword = formData.get('newPassword') as string;
const confirmPassword = formData.get('confirmPassword') as string;
if (!newPassword || newPassword.length < 6) {
return { error: 'Das Passwort muss mindestens 6 Zeichen lang sein.' };
}
if (newPassword === (process.env.DEFAULT_PASSWORD ?? 'welzheim')) {
return { error: 'Das Standard-Passwort darf nicht als neues Passwort verwendet werden.' };
}
if (newPassword !== confirmPassword) {
return { error: 'Die Passwörter stimmen nicht überein.' };
}
const hashed = await hashPassword(newPassword);
await updateBeoPassword(session.beoId, hashed);
await createSession({
kuerzel: session.kuerzel,
beoId: session.beoId,
beoName: session.beoName,
mustChangePassword: false,
isAuthenticated: true,
role: session.role ?? null,
});
redirect('/');
}