Files
logbuch/lib/auth.ts
T
admin 3fc5c9ff7a v1.5.0: utf8mb4-Migration, Rollen, phpMyAdmin, DB-Bereinigung
- Datenbank auf utf8mb4_unicode_ci migriert (migrate_to_utf8mb4.sh)
- beos: Spalte 'role' (kommagetrennte Rollen: guide, admin, key, deleted)
- BEO-Auswahl im Formular filtert nur noch role='guide'
- logbuch_objekte: ObjektName-Spalte entfernt, stattdessen JOIN auf objekte
- lib/db.ts: charset utf8mb4 in Connection-Pool
- Session und Auth um role-Feld erweitert
- compose.yml: phpMyAdmin mit Traefik unter /myadmin
- compose.yml: MySQL auf 127.0.0.1:3336 für SSH-Tunnel (lokale Entwicklung)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 09:34:38 +02:00

45 lines
1.1 KiB
TypeScript

import bcrypt from 'bcryptjs';
import { query } from './db';
export interface Beo {
id: number;
name: string;
vorname: string | null;
kürzel: string | null;
pw: string | null;
MustChangePassword: number;
role: string | null;
}
export async function getBeoByKuerzel(kuerzel: string): Promise<Beo | null> {
const rows = await query(
'SELECT id, name, vorname, `kürzel`, pw, MustChangePassword, role FROM beos WHERE `kürzel` = ?',
[kuerzel]
) as Beo[];
return rows[0] ?? null;
}
export async function verifyCredentials(
kuerzel: string,
password: string
): Promise<{ beo: Beo; valid: boolean } | null> {
const beo = await getBeoByKuerzel(kuerzel);
if (!beo) return null;
if (!beo.pw) {
const valid = password === 'logbuch123';
return { beo, valid };
}
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;
}