Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion React-Component/src/pages/home/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
display: flex;
gap: 2em;
margin-bottom: 50px;
background-color: blue;
}

.info {
Expand Down Expand Up @@ -316,4 +317,4 @@ footer {

.buy-now:hover img {
filter: brightness(0.9);
}
}
28 changes: 11 additions & 17 deletions React-Component/src/pages/home/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,25 @@ const Home = () => {
Helping your child develop <br />
critical thinking skills!
</h1>

<p>
We are a nonprofit organization empowering <br></br>children to find
their own success in STEM through <br></br>Chess, Math and Computer
Science.
We are a nonprofit organization empowering <br />
children to find their own success in STEM through <br />
Chess, Math and Computer Science.
</p>

<button className="donate-button" onClick={handleDonateButton}>
<strong>Donate</strong>
</button>
</div>
<div className="pic">
<img
src={Images.TreesGroup}
id="tree-group-img"
alt="ystemandchess mascot"
></img>
</div>

<img
src={Images.TreesGroup}
id="tree-group-img"
alt="ystemandchess mascot"
/>
</div>

<img
src={Images.LogoLineBr}
className="logo-break"
alt="line break"
></img>
<img src={Images.LogoLineBr} className="logo-break" alt="line break" />

<h1 id="floating-h1">Everyone is included.</h1>
<h1 id="floating-h1">Everyone is welcomed.</h1>
Expand Down Expand Up @@ -160,4 +154,4 @@ const Home = () => {
);
};

export default Home;
export default Home;
50 changes: 25 additions & 25 deletions React-Component/src/pages/student/student.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import React, {useState} from "react";
import React, { useState } from "react";
import "./Student.scss";
import {environment} from "../../environments/environment.js";

const Student = () => {
const chessSrc = environment.urls.chessClientURL;
const [movesAhead, setMovesAhead] = useState(5);
const chessSrc = environment.urls.chessClientURL;
const [movesAhead, setMovesAhead] = useState(5);

return (
<div className="chess-body">
<br />
<br />
<br />
<iframe src={chessSrc} title="Chessboard" height="500" width="500"/>
<br />
<br />
<br />
<button>New Game</button>
<button>Play with a computer</button>
<button>Undo</button>
<br />
<p>
The computer will think
<input type="number" min="1" step="1" max="30" value={movesAhead}/>
moves ahead of you
</p>
<br />
</div>
)
}
return (
<div className="chess-body">
<br />
<br />
<br />
<iframe src={chessSrc} title="Chessboard" height="500" width="500" />
<br />
<br />
<br />
<button>New Game</button>
<button>Play with a computer</button>
<button>Undo</button>
<br />
<p>
The computer will think
<input type="number" min="1" step="1" max="30" value={movesAhead} />
moves ahead of you
</p>
<br />
</div>
);
};

export default Student;
123 changes: 97 additions & 26 deletions middlewareNode/src/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const express = require("express");
const passport = require("passport");
const router = express.Router();
const crypto = require("crypto");
const jwt = require("jsonwebtoken");
const { check, validationResult } = require("express-validator");
const users = require("../models/users");
const Activities = require("../models/activities");
Expand All @@ -26,7 +27,7 @@ const {
} = require("../template/changePasswordTemplate");
const { sendMail } = require("../utils/nodemailer");
const { validator } = require("../utils/middleware");
const { MongoClient } = require('mongodb');
const { MongoClient } = require("mongodb");
const config = require("config");

// Cache database client to prevent repeated connections
Expand Down Expand Up @@ -110,7 +111,6 @@ router.post(
//Set the account created date for the new user
const currDate = new Date();


//Switch statement for functionality depending on role
if (role === "parent") {
let studentsArray = JSON.parse(students);
Expand Down Expand Up @@ -180,7 +180,7 @@ router.post(
console.error(error.message);
res.status(500).json("Server error");
}
},
}
);

// @route POST /user/children
Expand Down Expand Up @@ -236,7 +236,7 @@ router.post(
console.error(error.message);
res.status(500).json("Server error");
}
},
}
);
// @route POST /user/sendMail
// @desc sending the mail based on username and email
Expand Down Expand Up @@ -289,15 +289,15 @@ const updatePassword = async (body) => {
const result = await users.findOneAndUpdate(
{ username: body.username, email: body.email },
{ password: body.password },
{ new: true },
{ new: true }
);
return result;
};

// @route GET /user/mentorless/:keyword
// @desc for getting the mentorless students whose username matches keyword.
router.get("/mentorless", async (req, res) => {
const keyword = req.query.keyword || ''; // get the keyword
const keyword = req.query.keyword || ""; // get the keyword
try {
const db = await getDb();
const users = db.collection("users");
Expand All @@ -318,21 +318,28 @@ router.get("/mentorless", async (req, res) => {
// @desc if user is mentor, update its student username to the mentorship= query
// @access Public with jwt Authentication
router.put(
"/updateMentorship",
"/updateMentorship",
async (req, res, next) => {
passport.authenticate("jwt", { session: false }, async (err, user, info) => {
if (!user) {
return res.status(401).json({ message: "Unauthorized" });
passport.authenticate(
"jwt",
{ session: false },
async (err, user, info) => {
if (!user) {
return res.status(401).json({ message: "Unauthorized" });
}
req.user = user;
next();
}
req.user = user;
next();
})(req, res, next) // authenticate jwt
},
)(req, res, next); // authenticate jwt
},
async (req, res) => {
// get the student/mentor username
const mentorship = req.query.mentorship;
if (!mentorship) { // mentorship query is required
return res.status(400).json({ message: "Missing mentorship username in query" });
if (!mentorship) {
// mentorship query is required
return res
.status(400)
.json({ message: "Missing mentorship username in query" });
}

try {
Expand All @@ -359,23 +366,28 @@ router.put(
} catch (err) {
res.status(500).json({ error: err.message }); // error
}
}
}
);

// @route GET /user/getMentorship
// @desc if user is a student, responds with its mentor's object {username, firstName, lastName}
// @desc if user is a mentor, responds with its student's object {username, firstName, lastName}
// @access Public with jwt Authentication
router.get("/getMentorship",
router.get(
"/getMentorship",
async (req, res, next) => {
passport.authenticate("jwt", { session: false }, async (err, user, info) => {
if (!user) {
return res.status(401).json({ message: "Unauthorized" });
passport.authenticate(
"jwt",
{ session: false },
async (err, user, info) => {
if (!user) {
return res.status(401).json({ message: "Unauthorized" });
}
req.user = user;
next();
}
req.user = user;
next();
})(req, res, next) // authenticate jwt
},
)(req, res, next); // authenticate jwt
},
async (req, res) => {
try {
const db = await getDb();
Expand All @@ -402,4 +414,63 @@ router.get("/getMentorship",
}
);

module.exports = router;
router.get("/getStudent", async (req, res) => {
const keyword = req.query.keyword || "";

try {
const db = await getDb();
const users = db.collection("users");

const userList = await users
.find({
role: "student", // get student
username: { $regex: keyword, $options: "i" }, // case-insensitive match for username
})
.toArray();

res.json(userList.map((user) => user.username)); // return a list of the usernames
} catch (err) {
res.status(500).json({ error: err.message }); // error
}
});

// verify role

router.post("/verifyRole", async (req, res) => {
const { token } = req.body;

if (!token.login) {
return res.status(400).json({ error: "Missing token" });
}

const decoded = jwt.verify(token.login, config.get("indexKey"));

const user = await users
.findOne({ username: decoded.username })
.select("role");

if (!user) {
return res.status(404).json({ error: "User not found" });
}
console.log(decoded.role, user.role);
if (decoded.role === user.role) {
return res.json({ verified: true });
} else {
return res.status(403).json({ error: "Role mismatch", verified: false });
}
});

router.get("/getUser", async (req, res) => {
const username = req.query.username || "";
try {
const user = await users.findOne({ username }).select("-password");
if (!user) {
return res.status(404).json({ error: "User not found" });
}
return res.status(200).json(user);
} catch (err) {
return res.status(401).json({ error: err });
}
});

module.exports = router;
4 changes: 2 additions & 2 deletions react-ystemandchess/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
transform: {
'^.+\\.(ts|tsx|js|jsx)$': 'babel-jest',
"^.+\\.(ts|tsx|js|jsx)$": "babel-jest",
},
moduleNameMapper: {
'\\.(css|scss|sass)$': 'identity-obj-proxy',
Expand All @@ -13,4 +13,4 @@ module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
setupFilesAfterEnv: ['@testing-library/jest-dom'],
moduleDirectories: ['node_modules', 'src'],
};
};
2 changes: 1 addition & 1 deletion react-ystemandchess/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@
"volta": {
"node": "18.20.8"
}
}
}
2 changes: 1 addition & 1 deletion react-ystemandchess/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ function App() {
);
}

export default App;
export default App;
Loading