All checks were successful
Container-Image bauen und veröffentlichen / build-and-push (push) Successful in 5m15s
17 lines
1.2 KiB
TypeScript
17 lines
1.2 KiB
TypeScript
export function validateUserInput(input: unknown, create: boolean): string | null {
|
|
if (!input || typeof input !== "object" || Array.isArray(input)) return "Ungültige Benutzerdaten."
|
|
const data = input as Record<string, unknown>
|
|
if (create || data.email !== undefined) {
|
|
if (typeof data.email !== "string" || data.email.length > 254 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email.trim())) return "Bitte geben Sie eine gültige E-Mail-Adresse ein."
|
|
}
|
|
if (data.name !== undefined && data.name !== null && (typeof data.name !== "string" || data.name.length > 200)) return "Der Name darf maximal 200 Zeichen enthalten."
|
|
if (create || data.role !== undefined) {
|
|
if (data.role !== "ADMIN" && data.role !== "SUPER_ADMIN") return "Ungültige Rolle."
|
|
}
|
|
if (data.isActive !== undefined && typeof data.isActive !== "boolean") return "Ungültiger Aktivierungsstatus."
|
|
if (create || (data.password !== undefined && data.password !== "")) {
|
|
if (typeof data.password !== "string" || data.password.length < 12 || new TextEncoder().encode(data.password).length > 72) return "Das Passwort muss mindestens 12 Zeichen und höchstens 72 UTF-8-Bytes enthalten."
|
|
}
|
|
return null
|
|
}
|