Initial implementation: Logbuch Sternwarte Welzheim
Vollständige Next.js 16 Webanwendung als Logbuch für die Sternwarte Welzheim. 4 Kuppeln (West/Ost/Süd/Pluto), BEO-basierte Authentifizierung mit erzwungenem Passwort-Wechsel beim Erstlogin, MySQL-Backend, Docker-Deployment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
41
app/change-password/actions.ts
Normal file
41
app/change-password/actions.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
'use server';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getSession, createSession } from '@/lib/session';
|
||||
import { hashPassword } from '@/lib/auth';
|
||||
import { query } from '@/lib/db';
|
||||
|
||||
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 !== confirmPassword) {
|
||||
return { error: 'Die Passwörter stimmen nicht überein.' };
|
||||
}
|
||||
|
||||
const hashed = await hashPassword(newPassword);
|
||||
await query(
|
||||
'UPDATE beos SET Passwort = ?, MustChangePassword = 0 WHERE ID = ?',
|
||||
[hashed, session.beoId]
|
||||
);
|
||||
|
||||
await createSession({
|
||||
kuerzel: session.kuerzel,
|
||||
beoId: session.beoId,
|
||||
beoName: session.beoName,
|
||||
mustChangePassword: false,
|
||||
isAuthenticated: true,
|
||||
});
|
||||
|
||||
redirect('/');
|
||||
}
|
||||
Reference in New Issue
Block a user