feat: Add photo management features, duplicate detection, attempt limits, and admin deletion
CI / skip-ci-check (pull_request) Successful in 1m19s
CI / lint-and-type-check (pull_request) Failing after 1m37s
CI / test (pull_request) Successful in 2m16s
CI / build (pull_request) Failing after 1m46s
CI / secret-scanning (pull_request) Successful in 1m20s
CI / dependency-scan (pull_request) Successful in 1m27s
CI / sast-scan (pull_request) Successful in 2m29s
CI / workflow-summary (pull_request) Successful in 1m18s

- Add duplicate photo detection (file hash and URL checking)
- Add max attempts per photo with UI counter
- Simplify penalty system (auto-enable when points > 0)
- Prevent scores from going below 0
- Add admin photo deletion functionality
- Improve navigation with always-visible logout
- Prevent users from guessing their own photos
This commit is contained in:
2026-01-02 14:57:30 -05:00
commit 9640627972
69 changed files with 20858 additions and 0 deletions
@@ -0,0 +1,42 @@
import { NextRequest, NextResponse } from "next/server"
import { auth } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import { hashPassword } from "@/lib/utils"
export async function POST(
req: NextRequest,
{ params }: { params: Promise<{ userId: string }> }
) {
try {
const session = await auth()
if (!session || session.user.role !== "ADMIN") {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
const { userId } = await params
const { password } = await req.json()
if (!password || password.length < 6) {
return NextResponse.json(
{ error: "Password must be at least 6 characters" },
{ status: 400 }
)
}
const passwordHash = await hashPassword(password)
await prisma.user.update({
where: { id: userId },
data: { passwordHash },
})
return NextResponse.json({ success: true })
} catch (error) {
console.error("Error resetting password:", error)
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 }
)
}
}
+62
View File
@@ -0,0 +1,62 @@
import { NextRequest, NextResponse } from "next/server"
import { auth } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import { hashPassword } from "@/lib/utils"
export async function POST(req: NextRequest) {
try {
const session = await auth()
if (!session || session.user.role !== "ADMIN") {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
const { name, email, password, role } = await req.json()
if (!name || !email || !password) {
return NextResponse.json(
{ error: "Name, email, and password are required" },
{ status: 400 }
)
}
// Check if user already exists
const existingUser = await prisma.user.findUnique({
where: { email },
})
if (existingUser) {
return NextResponse.json(
{ error: "User with this email already exists" },
{ status: 400 }
)
}
const passwordHash = await hashPassword(password)
const user = await prisma.user.create({
data: {
name,
email,
passwordHash,
role: role || "USER",
},
})
return NextResponse.json(
{
id: user.id,
name: user.name,
email: user.email,
role: user.role,
},
{ status: 201 }
)
} catch (error) {
console.error("Error creating user:", error)
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 }
)
}
}