Skip to content

Commit

Permalink
Merge branch 'newform' of https://github.com/TEDx-SJEC/website into a…
Browse files Browse the repository at this point in the history
…dmin
  • Loading branch information
Vyshnav001 committed Sep 13, 2024
2 parents d6c7372 + 2302581 commit 6fc8c6f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 47 deletions.
Binary file modified prisma/dev.db
Binary file not shown.
Binary file modified prisma/dev.db-journal
Binary file not shown.
25 changes: 25 additions & 0 deletions prisma/migrations/20240913083428_verify/migration.sql
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;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ model Form {
name String
usn String
email String
emailVerified Boolean @default(false) @map("email_verified")
contact String?
designation String?
photo String @map("photo_url") // URL of the photo uploaded by the participan
Expand Down
File renamed without changes.
62 changes: 62 additions & 0 deletions src/app/api/(verification)/verify-mail/route.ts
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!" });
}
47 changes: 0 additions & 47 deletions src/app/api/verify-mail/route.ts

This file was deleted.

21 changes: 21 additions & 0 deletions src/middleware.ts
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*", "/"],
};

0 comments on commit 6fc8c6f

Please sign in to comment.