Skip to content

Commit a65ccd2

Browse files
committed
Linked login, and added packages
1 parent 3f6c8c8 commit a65ccd2

3 files changed

Lines changed: 485 additions & 7 deletions

File tree

client/src/pages/index.tsx

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import {
1414
Users,
1515
Workflow,
1616
} from "lucide-react";
17-
import React from "react";
17+
import { useRouter } from "next/router";
18+
import React, { useState } from "react";
19+
import { toast } from "sonner";
1820

1921
import { Badge } from "@/components/ui/badge";
2022
import { Button } from "@/components/ui/button";
2123
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
2224
import { Input } from "@/components/ui/input";
25+
import { useAuth } from "@/context/AuthContext";
26+
import api from "@/lib/api";
2327

2428
// Added this so that we can change colors more easily
2529
const COLORS = {
@@ -98,6 +102,30 @@ const scrollTo = (id: string) => {
98102
};
99103

100104
export default function AboutPage() {
105+
const router = useRouter();
106+
const { login, logout } = useAuth();
107+
const [username, setUsername] = useState("");
108+
const [password, setPassword] = useState("");
109+
110+
//function to return JWT
111+
const handleLogin = async () => {
112+
try {
113+
logout();
114+
const res = await api.post("/user/login/", {
115+
username,
116+
password,
117+
});
118+
const { access, refresh } = res.data;
119+
login(access, refresh);
120+
121+
toast("Logged in successfully");
122+
router.push("/home");
123+
} catch (err) {
124+
console.log(err);
125+
toast("Login failed. Please check your credentials.");
126+
}
127+
};
128+
101129
return (
102130
<div className={`min-h-screen scroll-smooth ${COLORS.background.main}`}>
103131
{/* nav */}
@@ -588,12 +616,14 @@ export default function AboutPage() {
588616
<label
589617
className={`text-sm font-medium ${COLORS.text.primary} mb-2 block`}
590618
>
591-
Email
619+
Username
592620
</label>
593621
<Input
594-
type="email"
595-
placeholder="your.email@university.edu"
596-
className={COLORS.border.input}
622+
id="username"
623+
type="username"
624+
placeholder="Enter Username here"
625+
required
626+
onChange={(e) => setUsername(e.target.value)}
597627
/>
598628
</div>
599629
<div>
@@ -603,16 +633,19 @@ export default function AboutPage() {
603633
Password
604634
</label>
605635
<Input
606-
type="password"
607-
placeholder="Create a secure password"
636+
id="password"
637+
placeholder="Enter Password here"
608638
className={COLORS.border.input}
639+
type="password"
640+
onChange={(e) => setPassword(e.target.value)}
609641
/>
610642
</div>
611643
</div>
612644

613645
<Button
614646
size="lg"
615647
className={`w-full ${COLORS.button.primary} ${COLORS.button.primaryHover} ${COLORS.text.white} py-6 text-lg`}
648+
onClick={handleLogin}
616649
>
617650
Sign In
618651
</Button>

server/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ dependencies = [
1414
"psycopg[binary,pool]~=3.2.13",
1515
"djangorestframework-simplejwt>=5.5.1",
1616
"pillow",
17+
"daphne>=4.2.1",
18+
"channels>=4.3.2",
1719
]
1820

1921
[dependency-groups]

0 commit comments

Comments
 (0)