Skip to content
Open
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
15 changes: 6 additions & 9 deletions quizzly-backend/src/createQuiz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
#include "httplib.h" // Include httplib for API handling
#include "mongo_instance.h"

// mongocxx::instance instance{};
//mongocxx::instance instance{};

// Function to insert quiz into MongoDB
bool createQuiz(const std::string &jsonString)
{
try
{
bool createQuiz(const std::string &jsonString) {
try {
// Initialize MongoDB
mongocxx::uri uri("mongodb+srv://ngelbloo:jxdnXevSBkquhl2E@se3313-cluster.7kcvssw.mongodb.net/");
mongocxx::client client(uri);
Expand All @@ -30,10 +28,9 @@ bool createQuiz(const std::string &jsonString)

// Return true if the insert was successful
return result ? true : false;
}
catch (const std::exception &e)
{

} catch (const std::exception &e) {
std::cerr << "MongoDB Error: " << e.what() << std::endl;
return false;
}
}
}
736 changes: 500 additions & 236 deletions quizzly-backend/src/main.cpp

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions quizzly-frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import Home from './pages/Home';
import { AuthProvider } from './context/AuthContext';
import JoinGame from './pages/JoinGame';
import GameLobby from './pages/GameLobby';
import PlayQuiz from './pages/PlayQuiz';

import Login from './pages/Login';
import Register from './pages/Register';
import Dashboard from './pages/Dashboard';
import CreateQuiz from './pages/CreateQuiz';
import EditQuiz from './pages/EditQuiz';
import QuizResults from './pages/QuizResults'

function AppContent() {
const location = useLocation();
const hideNavbarRoutes = ['/login', '/register', '/'];
const shouldHideNavbar = hideNavbarRoutes.includes(location.pathname);

return (
<div className="app">
{<Navbar />}
{!shouldHideNavbar && <Navbar />}
<main className="main-content">
<Routes>
<Route path="/" element={<Home />} />
Expand All @@ -26,7 +32,9 @@ function AppContent() {
<Route path="/register" element={<Register />} />
<Route path="/dashboard" element={<Dashboard />} />
<Route path="/create-quiz" element={<CreateQuiz />} />
<Route path="/game-lobby/:id" element={<GameLobby />} />
<Route path="/game-lobby/:id/:lobby" element={<GameLobby />} />
<Route path="/results/:lobbyCode" element={<QuizResults />} />
<Route path="/play-quiz/:id/:lobby" element={<PlayQuiz />} />
<Route path="/edit-quiz/:id" element={<EditQuiz />} />
<Route path="/home" element={<Home />} />
<Route path="*" element={<div>Page not found</div>} />
Expand Down
18 changes: 18 additions & 0 deletions quizzly-frontend/src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ const Footer = () => {
</li>
</ul>
</div>

<div className="footer-section">
<h3 className="footer-heading">Connect</h3>
<div className="social-links">
<a href="https://twitter.com" target="_blank" rel="noopener noreferrer">
<i className="fa fa-twitter"></i>
</a>
<a href="https://facebook.com" target="_blank" rel="noopener noreferrer">
<i className="fa fa-facebook"></i>
</a>
<a href="https://instagram.com" target="_blank" rel="noopener noreferrer">
<i className="fa fa-instagram"></i>
</a>
<a href="https://linkedin.com" target="_blank" rel="noopener noreferrer">
<i className="fa fa-linkedin"></i>
</a>
</div>
</div>
</div>

<div className="footer-bottom">
Expand Down
20 changes: 9 additions & 11 deletions quizzly-frontend/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Navbar = () => {
try {
await logout();
closeMenu(); // Close the menu when logging out
navigate('/');
navigate('/login');
} catch (error) {
console.error('Failed to log out', error);
}
Expand Down Expand Up @@ -52,31 +52,29 @@ const Navbar = () => {
Join Game
</Link>
</li>
{currentUser ? (


<>
<li className="navbar-item">
<Link to="/dashboard" className="navbar-link" onClick={closeMenu}>
Dashboard
</Link>
</li>
<li className="navbar-item">
<Link to="/create-quiz" className="navbar-link" onClick={closeMenu}>
Create Quiz
</Link>
</li>
<li className="navbar-item">
<button className="navbar-button logout-button" onClick={handleLogout}>
Logout
</button>
</li>
</>
) : (
<li className="navbar-item">
<Link to="/login" className="navbar-button logout-button" onClick={closeMenu}>
Login
</Link>
</li>
)}
</ul>
</div>
</nav>
);
};

export default Navbar;
export default Navbar;
71 changes: 33 additions & 38 deletions quizzly-frontend/src/context/AuthContext.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// AuthContext.jsx
import { createContext, useContext, useState, useEffect } from "react";
import { createContext, useContext, useState, useEffect } from 'react';

const AuthContext = createContext();

Expand All @@ -13,79 +13,74 @@ export function AuthProvider({ children }) {

// On mount, load any stored user from localStorage
useEffect(() => {
const storedUser = localStorage.getItem("quizzlyUser");
const storedUser = localStorage.getItem('quizzlyUser');
if (storedUser) {
setCurrentUser(/*JSON.parse(*/storedUser);
//setCurrentUser(JSON.parse(storedUser));
console.log("Current user: ", storedUser);
setCurrentUser(storedUser);
}
setLoading(false);
}, []);

// Register function: sends plaintext password to backend
const register = async (name, email, password) => {
const response = await fetch(
`${import.meta.env.VITE_BACKEND_URL}/api/register`,
{
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name,
email,
password,
}),
}
);

const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/register`, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name,
email,
password
})
});

const data = await response.json();
if (response.ok && data.success) {
// Assuming your backend returns the created user object
setCurrentUser(data.user);
localStorage.setItem("quizzlyUser", JSON.stringify(data.user));
localStorage.setItem('quizzlyUser', JSON.stringify(data.user));
return data.user;
} else {
throw new Error(data.error || "Registration failed on server");
throw new Error(data.error || 'Registration failed on server');
}
};

// Login function: sends plaintext password to backend for verification
const login = async (email, password) => {
const response = await fetch(
`${import.meta.env.VITE_BACKEND_URL}/api/login`,
{
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email, password }),
}
);

const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/login`, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email, password })
});

const data = await response.json();
if (response.ok && data.success) {
setCurrentUser(data.user);
localStorage.setItem("quizzlyUser", JSON.stringify(data.user));
localStorage.setItem('quizzlyUser', JSON.stringify(data.user));
return data.user;
} else {
throw new Error(data.error || "Login failed on server");
throw new Error(data.error || 'Login failed on server');
}
};

const logout = async () => {
// Clear local auth state
setCurrentUser(null);
localStorage.removeItem("quizzlyUser");
console.log("Current user: ", localStorage.getItem("quizzlyUser"));
localStorage.removeItem('quizzlyUser');
};

const value = {
currentUser,
login,
register,
logout,
loading,
loading
};

return (
Expand Down
4 changes: 1 addition & 3 deletions quizzly-frontend/src/pages/CreateQuiz.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ const CreateQuiz = () => {

const handleSubmit = async (e) => {
e.preventDefault();

// should check if quiz name is unique

if (step === 1) {
if (!quizData.title.trim() || !quizData.description.trim() || !quizData.category) {
Expand All @@ -162,7 +160,7 @@ const CreateQuiz = () => {
alert('Your quiz needs at least one question.');
return;
}

const formattedQuiz = {
title: quizData.title,
description: quizData.description,
Expand Down
Loading