ilia 9640627972
Some checks failed
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
feat: Add photo management features, duplicate detection, attempt limits, and admin deletion
- 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
2026-01-02 14:57:30 -05:00

54 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { auth } from "@/lib/auth"
import { prisma } from "@/lib/prisma"
import bcrypt from "bcryptjs"
import { hashPassword } from "@/lib/utils"
export async function POST(req: NextRequest) {
try {
const session = await auth()
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
const { currentPassword, newPassword } = await req.json()
if (!currentPassword || !newPassword) {
return NextResponse.json(
{ error: "Current password and new password are required" },
{ status: 400 }
)
}
const user = await prisma.user.findUnique({
where: { id: session.user.id },
})
if (!user) {
return NextResponse.json({ error: "User not found" }, { status: 404 })
}
const isValid = await bcrypt.compare(currentPassword, user.passwordHash)
if (!isValid) {
return NextResponse.json({ error: "Current password is incorrect" }, { status: 400 })
}
const newPasswordHash = await hashPassword(newPassword)
await prisma.user.update({
where: { id: session.user.id },
data: { passwordHash: newPasswordHash },
})
return NextResponse.json({ success: true })
} catch (error) {
console.error("Error changing password:", error)
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 }
)
}
}