Skip to content

Commit

Permalink
feat: added course selection system
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew committed Aug 20, 2024
1 parent 7c3a743 commit b270f66
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/app/[lang]/(mods-pages)/apps/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const AppList = ({ params: { lang } }: LangProps) => {
className="flex flex-row flex-1 items-center space-x-2"
target={app.target}
>
<div className="p-3 rounded-full bg-indigo-100 text-indigo-800 grid place-items-center">
<div className="p-3 rounded-full bg-nthu-200 text-nthu-800 grid place-items-center">
<app.Icon size={16} />
</div>
<div className="flex flex-col gap-1 flex-1">
<h2 className="text-base font-medium text-gray-600 dark:text-neutral-400">
<h2 className="text-base font-medium text-muted-foreground">
{lang == "zh" ? app.title_zh : app.title_en}
</h2>
</div>
Expand Down
40 changes: 33 additions & 7 deletions src/app/[lang]/ais-redirect/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSettings } from "@/hooks/contexts/settings";
import { useEffect, useState } from "react";
import { AISLoading } from "@/components/Pages/AISLoading";
import { AISError } from "@/components/Pages/AISError";
import { useParams } from "next/navigation";
import { useParams, useSearchParams } from "next/navigation";
import { useHeadlessAIS } from "@/hooks/contexts/useHeadlessAIS";
import { AISNotLoggedIn } from "@/components/Pages/AISNotLoggedIn";

Expand All @@ -28,13 +28,13 @@ import { AISNotLoggedIn } from "@/components/Pages/AISNotLoggedIn";

const RedirectPage = ({}) => {
const params = useParams();
const searchParams = useSearchParams();
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);
const { getACIXSTORE, ais } = useHeadlessAIS();

const path = params.path instanceof Array ? params.path : [params.path];

const redirect_url = `https://www.ccxp.nthu.edu.tw/ccxp/INQUIRE/${path.join("/")}?ACIXSTORE=`;
useEffect(() => {
(async () => {
const token = await getACIXSTORE();
Expand All @@ -44,14 +44,40 @@ const RedirectPage = ({}) => {
return;
}

//redirect user
const link = document.createElement("a");
link.href = redirect_url + token;
link.click();
//handle custom url (but strictly for ccxp)
if (path[0] === "custom") {
const url = searchParams.get("url");
if (!url) {
setLoading(false);
setError("Invalid URL");
return;
}

// check if the url is a valid ccxp url, prevent phishing for ACIXSTORE
if (!url.startsWith("https://www.ccxp.nthu.edu.tw")) {
setLoading(false);
setError("Invalid URL");
return;
}

// Redirect user
const redirect_url = url + `?ACIXSTORE=${token}`;
console.log(redirect_url);
const link = document.createElement("a");
link.href = redirect_url;
link.click();
setLoading(false);
} else {
//redirect user
const redirect_url = `https://www.ccxp.nthu.edu.tw/ccxp/INQUIRE/${path.join("/")}?ACIXSTORE=`;
const link = document.createElement("a");
link.href = redirect_url + token;
link.click();
}

setLoading(false);
})();
}, [getACIXSTORE, redirect_url]);
}, [getACIXSTORE, searchParams, path]);

if (!ais.enabled) return <AISNotLoggedIn />;
if (loading) return <AISLoading />;
Expand Down
11 changes: 0 additions & 11 deletions src/app/api/scrape-enrollment-status/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import supabase from "@/config/supabase";
import supabase_server from "@/config/supabase_server";

export const GET = async (request: NextRequest, _try = 0) => {
const authHeader = request.headers.get("authorization");

if (
process.env.NODE_ENV == "production" &&
authHeader !== `Bearer ${process.env.CRON_SECRET}`
) {
return new Response("Unauthorized", {
status: 401,
});
}

const user = await signInToCCXP(
process.env.DONER_STUDENTID!,
process.env.DONER_PASSWORD!,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Today/TodaySchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const TodaySchedule: FC<{
{applist.map((app, index) => (
<Link href={app.href} key={index}>
<div className="flex flex-col items-center justify-center p-2 gap-2 w-16">
<div className="p-3 rounded-full bg-indigo-100 text-indigo-800 grid place-items-center">
<div className="p-3 rounded-full bg-nthu-200 text-nthu-800 grid place-items-center">
<app.Icon size={20} />
</div>
<div className="flex flex-col gap-1 flex-1">
Expand Down
15 changes: 15 additions & 0 deletions src/const/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
WalletCards,
Gamepad,
Paperclip,
TicketCheck,
CalendarCheck2,
} from "lucide-react";

export const apps = [
Expand Down Expand Up @@ -50,6 +52,19 @@ export const apps = [
Icon: Clipboard,
ais: true,
},
{
id: "coursereg",
title_zh: "選課系統",
title_en: "Course Selection System",
href:
"/ais-redirect/custom?url=" +
encodeURIComponent(
"https://www.ccxp.nthu.edu.tw/ccxp/COURSE/JH/7/7.1/7.1.3/JH713001.php",
),
Icon: CalendarCheck2,
target: "_blank",
ais: true,
},
{
id: "eform",
title_zh: "電子表單系統",
Expand Down

0 comments on commit b270f66

Please sign in to comment.