-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'newform' of https://github.com/TEDx-SJEC/website into a…
…dmin
- Loading branch information
Showing
8 changed files
with
109 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- RedefineTables | ||
PRAGMA defer_foreign_keys=ON; | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Form" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"name" TEXT NOT NULL, | ||
"usn" TEXT NOT NULL, | ||
"email" TEXT NOT NULL, | ||
"email_verified" BOOLEAN NOT NULL DEFAULT false, | ||
"contact" TEXT, | ||
"designation" TEXT, | ||
"photo_url" TEXT NOT NULL, | ||
"college_id_card" TEXT, | ||
"entity_name" TEXT NOT NULL, | ||
"referral_id" TEXT, | ||
"created_by_id" TEXT NOT NULL, | ||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT "Form_created_by_id_fkey" FOREIGN KEY ("created_by_id") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "Form_referral_id_fkey" FOREIGN KEY ("referral_id") REFERENCES "Referral" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Form" ("college_id_card", "contact", "created_at", "created_by_id", "designation", "email", "entity_name", "id", "name", "photo_url", "referral_id", "usn") SELECT "college_id_card", "contact", "created_at", "created_by_id", "designation", "email", "entity_name", "id", "name", "photo_url", "referral_id", "usn" FROM "Form"; | ||
DROP TABLE "Form"; | ||
ALTER TABLE "new_Form" RENAME TO "Form"; | ||
PRAGMA foreign_keys=ON; | ||
PRAGMA defer_foreign_keys=OFF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import sendEmail from "@/utils/sendMail"; | ||
import prisma from "@/server/db"; | ||
|
||
export async function POST(req: NextRequest) { | ||
const body = await req.json(); | ||
console.log(body); | ||
const { identifier, otp } = body; | ||
try { | ||
await prisma.$transaction(async (tx) => { | ||
const request = await tx.verificationRequest.findFirst({ | ||
where: { | ||
identifier, | ||
otp, | ||
expires: { | ||
gte: new Date(), | ||
}, | ||
}, | ||
orderBy: { | ||
created_at: "desc", | ||
|
||
}, | ||
}); | ||
|
||
if (!request) { | ||
throw new Error("Invalid or expired OTP"); | ||
} | ||
|
||
await tx.form.updateMany({ | ||
where: { | ||
email: identifier, | ||
}, | ||
data: { | ||
emailVerified: true, | ||
}, | ||
}); | ||
|
||
await tx.verificationRequest.deleteMany({ | ||
where: { | ||
identifier, | ||
}, | ||
}); | ||
}); | ||
|
||
return NextResponse.json( | ||
{ | ||
message: "OTP verified successfully back!", | ||
status: 200, | ||
}, | ||
{ status: 200 } | ||
); | ||
} catch (error: any) { | ||
return NextResponse.json( | ||
{ message: error.message, status: 400 }, | ||
{ status: 200 } | ||
); | ||
} | ||
} | ||
|
||
export async function GET() { | ||
return NextResponse.json({ message: "Hello from the Send mail!" }); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
export { default } from "next-auth/middleware"; | ||
import { getToken } from "next-auth/jwt"; | ||
|
||
// This function can be marked `async` if using `await` inside | ||
export async function middleware(request: NextRequest) { | ||
const token = await getToken({ req: request }); | ||
const url = request.nextUrl; | ||
|
||
if (url.pathname === "/admin") { | ||
if (token?.role!=="ADMIN") { | ||
return NextResponse.redirect(new URL("/", request.url)); | ||
} | ||
} | ||
} | ||
|
||
// See "Matching Paths" below to learn more | ||
export const config = { | ||
matcher: ["/:path*", "/"], | ||
}; |