Skip to content

Commit 1c703d4

Browse files
Merge branch 'main' into fp03_298_day-2
2 parents 4ab769f + eb11de4 commit 1c703d4

16 files changed

+1084
-55
lines changed

components/Form.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
Button,
3+
Flex,
4+
FormControl,
5+
FormLabel,
6+
Input,
7+
InputGroup,
8+
InputRightElement,
9+
} from "@chakra-ui/react";
10+
import React from "react";
11+
import styles from "../styles/signup.module.css"
12+
13+
const Form = ({ handleInput, fullname, email, password }) => {
14+
const [show, setShow] = React.useState(false);
15+
const handleClick = () => setShow(!show);
16+
17+
return (
18+
<Flex gap="2" flexDirection={"column"}>
19+
{/* <FormControl>
20+
<FormLabel>Full Name</FormLabel>
21+
<Input
22+
type="text"
23+
name="name"
24+
value={fullname}
25+
onChange={handleInput}
26+
/> */}
27+
<div className={styles.inputBox}>
28+
<input type="email" name="email" value={email} onChange={handleInput} required="required" />
29+
<span>Full Name</span>
30+
<i />
31+
</div>
32+
{/* </FormControl>
33+
<div className={styles.inputBox}>
34+
<FormLabel>Email address</FormLabel>
35+
<Input type="email" name="email" value={email} onChange={handleInput}/>
36+
</div>
37+
*/}
38+
39+
<div className={styles.inputBox}>
40+
<input type="email" name="email" value={email} onChange={handleInput} required="required" />
41+
<span>Email</span>
42+
<i />
43+
</div>
44+
<div className={styles.inputBox}>
45+
<input type="email" name="email" value={email} onChange={handleInput} required="required" />
46+
<span>Password</span>
47+
<i />
48+
</div>
49+
50+
51+
</Flex>
52+
);
53+
};
54+
55+
export default Form;

components/navbar.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import Link from "next/link";
2-
import styles from '../styles/Navbar.module.css';
1+
import React, { useEffect } from "react";
2+
import styles from "../styles/Navbar.module.css";
3+
import { Button, Link } from "@chakra-ui/react";
34

4-
export default function Navbar() {
5+
const Navbar = () => {
6+
return (
7+
<div>
8+
<nav className={styles.nav}>
9+
<ul className={styles.items}>
10+
<li>Home</li>
11+
<li>teacher</li>
12+
<li>student</li>
13+
<li>courses</li>
14+
</ul>
15+
</nav>
16+
</div>
17+
);
18+
};
519

6-
return (
7-
<div className={styles.container}>
8-
<Link href="/">Home</Link>
9-
<Link href="signin">Signin</Link>
10-
<Link href="signup">Signup</Link>
11-
</div>
12-
)
13-
14-
}
20+
export default Navbar;

middleware/authorization.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const jwt = require("jsonwebtoken");
2+
const secrectKey = process.env.SECRECTTOKEN;
3+
4+
const AuthMiddleware = (req, res, next) => {
5+
const token = req.headers["authorization"];
6+
let decode = jwt.decode(token, secrectKey);
7+
8+
if (decode.role === "admin" || decode.role === "teacher") {
9+
next();
10+
} else {
11+
return res.status(403).send("you are not allowed to do this operation.");
12+
}
13+
};
14+
15+
const userAuthMiddleware = (req, res, next) => {
16+
const token = req.headers["authorization"];
17+
let decode = jwt.decode(token, secrectKey);
18+
if (decode.role === "student") {
19+
next();
20+
} else {
21+
return res.status(403).send("you are not allowed to do this operation.");
22+
}
23+
};
24+
25+
module.exports = { AuthMiddleware, userAuthMiddleware };

models/users.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const mongoose = require("mongoose");
2+
3+
const usersSchema = new mongoose.Schema(
4+
{
5+
name: { type: String, required: true },
6+
7+
email: {
8+
type: String,
9+
unique: true,
10+
required: true,
11+
},
12+
13+
password: { type: String, required: true },
14+
15+
role: {
16+
type: String,
17+
enum: ["admin", "student", "teacher"],
18+
default: "student",
19+
},
20+
21+
status: {
22+
type: String,
23+
enum: ["pending", "approved", "rejected"],
24+
default: "approved",
25+
},
26+
},
27+
{
28+
timestamps: true,
29+
versionKey: false,
30+
}
31+
);
32+
33+
mongoose.models = {};
34+
module.exports = mongoose.model("User", usersSchema);

0 commit comments

Comments
 (0)