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:
19
lib/auth.ts
19
lib/auth.ts
@@ -2,16 +2,17 @@ import bcrypt from 'bcryptjs';
|
||||
import { query } from './db';
|
||||
|
||||
export interface Beo {
|
||||
ID: number;
|
||||
Kuerzel: string;
|
||||
Name: string;
|
||||
Passwort: string | null;
|
||||
id: number;
|
||||
name: string;
|
||||
vorname: string | null;
|
||||
kürzel: string | null;
|
||||
pw: string | null;
|
||||
MustChangePassword: number;
|
||||
}
|
||||
|
||||
export async function getBeoByKuerzel(kuerzel: string): Promise<Beo | null> {
|
||||
const rows = await query(
|
||||
'SELECT ID, Kuerzel, Name, Passwort, MustChangePassword FROM beos WHERE Kuerzel = ?',
|
||||
'SELECT id, name, vorname, `kürzel`, pw, MustChangePassword FROM beos WHERE `kürzel` = ?',
|
||||
[kuerzel]
|
||||
) as Beo[];
|
||||
return rows[0] ?? null;
|
||||
@@ -24,15 +25,19 @@ export async function verifyCredentials(
|
||||
const beo = await getBeoByKuerzel(kuerzel);
|
||||
if (!beo) return null;
|
||||
|
||||
if (!beo.Passwort) {
|
||||
if (!beo.pw) {
|
||||
const valid = password === 'logbuch123';
|
||||
return { beo, valid };
|
||||
}
|
||||
|
||||
const valid = await bcrypt.compare(password, beo.Passwort);
|
||||
const valid = await bcrypt.compare(password, beo.pw);
|
||||
return { beo, valid };
|
||||
}
|
||||
|
||||
export async function hashPassword(password: string): Promise<string> {
|
||||
return bcrypt.hash(password, 10);
|
||||
}
|
||||
|
||||
export function getBeoDisplayName(beo: Beo): string {
|
||||
return beo.vorname ? `${beo.vorname} ${beo.name}` : beo.name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user