Initial commit: FL-Akademie LMS mit Docker, Admin, Portal und Dokumentation.

Made-with: Cursor
This commit is contained in:
lo
2026-04-13 23:17:07 +02:00
commit d3367f0046
66 changed files with 3641 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import NextAuth from "next-auth";
import { authOptions } from "@/lib/auth-options";
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };

38
app/api/enroll/route.ts Normal file
View File

@@ -0,0 +1,38 @@
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth-options";
import { prisma } from "@/lib/prisma";
export async function POST(req: Request) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "Nicht angemeldet." }, { status: 401 });
}
const body = (await req.json().catch(() => null)) as { courseSlug?: string } | null;
const courseSlug = body?.courseSlug?.trim();
if (!courseSlug) {
return NextResponse.json({ error: "courseSlug fehlt." }, { status: 400 });
}
const course = await prisma.course.findFirst({
where: { slug: courseSlug, published: true },
});
if (!course) {
return NextResponse.json({ error: "Kurs nicht gefunden." }, { status: 404 });
}
if (course.priceCents > 0) {
return NextResponse.json({ error: "payment_required" }, { status: 402 });
}
await prisma.enrollment.upsert({
where: {
userId_courseId: { userId: session.user.id, courseId: course.id },
},
update: {},
create: { userId: session.user.id, courseId: course.id },
});
return NextResponse.json({ ok: true });
}

View File

@@ -0,0 +1,34 @@
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import bcrypt from "bcryptjs";
import { authOptions } from "@/lib/auth-options";
import { prisma } from "@/lib/prisma";
export async function POST(req: Request) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "Nicht angemeldet." }, { status: 401 });
}
const body = (await req.json().catch(() => null)) as {
currentPassword?: string;
newPassword?: string;
} | null;
const currentPassword = body?.currentPassword ?? "";
const newPassword = body?.newPassword ?? "";
if (!currentPassword || newPassword.length < 8) {
return NextResponse.json({ error: "Ungültige Eingaben." }, { status: 400 });
}
const user = await prisma.user.findUnique({ where: { id: session.user.id } });
if (!user) return NextResponse.json({ error: "Nutzer nicht gefunden." }, { status: 404 });
const ok = await bcrypt.compare(currentPassword, user.passwordHash);
if (!ok) return NextResponse.json({ error: "Aktuelles Passwort ist falsch." }, { status: 403 });
const passwordHash = await bcrypt.hash(newPassword, 10);
await prisma.user.update({ where: { id: user.id }, data: { passwordHash } });
return NextResponse.json({ ok: true });
}

View File

@@ -0,0 +1,25 @@
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth-options";
import { prisma } from "@/lib/prisma";
import { clearCourseProgress } from "@/lib/certificates";
export async function POST(req: Request) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "Nicht angemeldet." }, { status: 401 });
}
const body = (await req.json().catch(() => null)) as { courseId?: string } | null;
const courseId = body?.courseId?.trim();
if (!courseId) return NextResponse.json({ error: "courseId fehlt." }, { status: 400 });
const enrollment = await prisma.enrollment.findUnique({
where: { userId_courseId: { userId: session.user.id, courseId } },
});
if (!enrollment) return NextResponse.json({ error: "Nicht eingeschrieben." }, { status: 403 });
await clearCourseProgress(session.user.id, courseId);
return NextResponse.json({ ok: true });
}

57
app/api/progress/route.ts Normal file
View File

@@ -0,0 +1,57 @@
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth-options";
import { prisma } from "@/lib/prisma";
import { syncCertificateForCourse } from "@/lib/certificates";
export async function POST(req: Request) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "Nicht angemeldet." }, { status: 401 });
}
const body = (await req.json().catch(() => null)) as {
lessonId?: string;
completed?: boolean;
} | null;
const lessonId = body?.lessonId?.trim();
if (!lessonId) {
return NextResponse.json({ error: "lessonId fehlt." }, { status: 400 });
}
const lesson = await prisma.lesson.findUnique({
where: { id: lessonId },
include: { module: { include: { course: true } } },
});
if (!lesson) {
return NextResponse.json({ error: "Lektion nicht gefunden." }, { status: 404 });
}
const courseId = lesson.module.course.id;
const enrollment = await prisma.enrollment.findUnique({
where: { userId_courseId: { userId: session.user.id, courseId } },
});
if (!enrollment) {
return NextResponse.json({ error: "Nicht eingeschrieben." }, { status: 403 });
}
const completed =
typeof body?.completed === "boolean" ? body.completed : true;
if (completed) {
await prisma.lessonProgress.upsert({
where: { userId_lessonId: { userId: session.user.id, lessonId } },
update: { completedAt: new Date() },
create: { userId: session.user.id, lessonId, completedAt: new Date() },
});
await syncCertificateForCourse(session.user.id, courseId);
} else {
await prisma.lessonProgress.deleteMany({
where: { userId: session.user.id, lessonId },
});
await syncCertificateForCourse(session.user.id, courseId);
}
return NextResponse.json({ ok: true });
}