Adapt to existing beos table in database sternwarte
Column mapping: id, name/vorname, kürzel (with umlaut), pw instead of the planned schema. DB_NAME changed to sternwarte. create_table.sql no longer creates beos, only the three new logbuch tables. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,9 @@ import { query } from '@/lib/db';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const rows = await query('SELECT ID, Kuerzel, Name FROM beos ORDER BY Name ASC');
|
||||
const rows = await query(
|
||||
'SELECT id AS ID, `kürzel` AS Kuerzel, CONCAT(IFNULL(vorname, \'\'), IF(vorname IS NOT NULL, \' \', \'\'), name) AS Name FROM beos WHERE `kürzel` IS NOT NULL ORDER BY name ASC'
|
||||
) as { ID: number; Kuerzel: string; Name: string }[];
|
||||
return NextResponse.json(rows);
|
||||
} catch (error) {
|
||||
console.error('GET /api/beos:', error);
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function changePassword(
|
||||
|
||||
const hashed = await hashPassword(newPassword);
|
||||
await query(
|
||||
'UPDATE beos SET Passwort = ?, MustChangePassword = 0 WHERE ID = ?',
|
||||
'UPDATE beos SET pw = ?, MustChangePassword = 0 WHERE id = ?',
|
||||
[hashed, session.beoId]
|
||||
);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use server';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
import { verifyCredentials } from '@/lib/auth';
|
||||
import { verifyCredentials, getBeoDisplayName } from '@/lib/auth';
|
||||
import { createSession } from '@/lib/session';
|
||||
|
||||
export async function login(
|
||||
@@ -22,14 +22,14 @@ export async function login(
|
||||
}
|
||||
|
||||
await createSession({
|
||||
kuerzel: result.beo.Kuerzel,
|
||||
beoId: result.beo.ID,
|
||||
beoName: result.beo.Name,
|
||||
kuerzel: result.beo.kürzel ?? kuerzel,
|
||||
beoId: result.beo.id,
|
||||
beoName: getBeoDisplayName(result.beo),
|
||||
mustChangePassword: result.beo.MustChangePassword === 1,
|
||||
isAuthenticated: true,
|
||||
});
|
||||
|
||||
if (result.beo.MustChangePassword === 1) {
|
||||
if (result.beo.MustChangePassword === 1 || !result.beo.pw) {
|
||||
redirect('/change-password');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user