diff --git a/public/checklist.html b/public/checklist.html
index fcc6057..3e9e83c 100644
--- a/public/checklist.html
+++ b/public/checklist.html
@@ -185,6 +185,13 @@
${watchedDate} |
`;
+ // Set initial row color based on watched state
+ if (watchedMovie) {
+ movieRow.style.backgroundColor = 'rgba(144, 238, 144, 0.6)'; // Lighter light green with transparency
+ } else {
+ movieRow.style.backgroundColor = 'rgba(255, 99, 71, 0.6)'; // Lighter light red with transparency
+ }
+
movieTableBody.appendChild(movieRow);
movieRow.addEventListener('click', (event) => {
@@ -199,10 +206,14 @@
checkbox.addEventListener('change', async (event) => {
const isChecked = event.target.checked;
const watchedDateCell = document.getElementById(`watched-date-${movie.imdb_id}`);
+ const row = event.target.closest('tr'); // Get the parent row
+
if (isChecked) {
watchedDateCell.textContent = new Date().toLocaleString();
+ row.style.backgroundColor = 'rgba(144, 238, 144, 0.6)'; // Apply light green with transparency
} else {
watchedDateCell.textContent = '';
+ row.style.backgroundColor = 'rgba(255, 99, 71, 0.6)'; // Apply light red with transparency
}
await fetch('/api/movies/users/updateWatchedMovies', {
diff --git a/public/index.html b/public/index.html
index 788981f..a7a2984 100644
--- a/public/index.html
+++ b/public/index.html
@@ -101,7 +101,7 @@
window.location.href = '/movies.html'; // Redirect to movies page on success
} else {
const error = await res.json();
- alert(`Login failed: ${error.message}`);
+ alert(`${error.message}`);
}
});
diff --git a/public/register.html b/public/register.html
index beca2c3..02dd6f7 100644
--- a/public/register.html
+++ b/public/register.html
@@ -78,11 +78,12 @@
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
+ const verifoof = document.getElementById('verifoof').value;
const res = await fetch('/api/users/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ name, email, password })
+ body: JSON.stringify({ name, email, password, verifoof })
});
const responseMessageElement = document.getElementById('response-message');
diff --git a/public/user-stat.html b/public/user-stat.html
index b80a719..165c132 100644
--- a/public/user-stat.html
+++ b/public/user-stat.html
@@ -180,7 +180,7 @@
movies.forEach(movie => {
const movieItem = document.createElement('li');
movieItem.classList.add('list-group-item');
- movieItem.textContent = movie.movieTitle;
+ movieItem.textContent = movie.title;
movieList.appendChild(movieItem);
});
diff --git a/routes/users.js b/routes/users.js
index ad19303..bad085b 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -91,54 +91,43 @@ function verifyToken(req, res, next) {
});
}
-// Get user stats with watched movie titles and details from OMDb
+// Get user stats with watched movie titles and details from the movies collection
router.get("/stats", verifyToken, async (req, res) => {
try {
// Fetch all users
const users = await User.find();
- // Fetch all movies
+ // Fetch all movies from the database
const allMovies = await Movie.find();
const totalMoviesCount = allMovies.length;
if (totalMoviesCount === 0) {
- return res.status(400).json({ message: "No movies available in the database." });
+ return res.status(400).json({ message: "Aucun films disponible." });
}
// Build stats for each user
- const userStats = await Promise.all(users.map(async (user) => {
- // Get watched movie IMDb IDs
+ const userStats = users.map((user) => {
+ // Get watched movies with details from the database
const watchedMovies = user.watchedMovies
- .map((wm) => wm.imdb_id) // Extract IMDb ID
- .filter((imdb_id) => allMovies.some((m) => m.imdb_id === imdb_id)); // Ensure the movie exists in the database
+ .map((wm) => allMovies.find((m) => m.imdb_id === wm.imdb_id)) // Match movie details
+ .filter(Boolean); // Remove any `undefined` values (if movie is not found)
const watchedCount = watchedMovies.length;
const watchedRatio = ((watchedCount / totalMoviesCount) * 100).toFixed(1);
- // Fetch movie details from OMDb for each watched movie
- const movieDetailsPromises = watchedMovies.map(async (imdb_id) => {
- try {
- const movieTitle = (await fetchMovieDetailsFromOmdb(imdb_id)).title;
- return {
- imdb_id,
- movieTitle
- };
- } catch (err) {
- console.error(`Error fetching details for movie with IMDb ID: ${imdb_id}`);
- return { imdb_id, error: err.message };
- }
- });
-
- const movieTitle = await Promise.all(movieDetailsPromises);
+ const watchedMoviesDetails = watchedMovies.map((movie) => ({
+ imdb_id: movie.imdb_id,
+ title: movie.title
+ }));
return {
name: user.name,
watchedCount,
totalMoviesCount,
watchedRatio: `${watchedRatio}%`,
- watchedMovies: movieTitle // Include movie details
+ watchedMovies: watchedMoviesDetails // Include movie details
};
- }));
+ });
res.json(userStats);
} catch (err) {
@@ -149,12 +138,30 @@ router.get("/stats", verifyToken, async (req, res) => {
// Register User
router.post("/register", async (req, res) => {
- const { name, email, password, role } = req.body;
+ const { name, email, password, role, verifoof } = req.body;
+ function registerVerification() {
+ return woof.includes(verifoof);
+ }
+ console.log("Verification input:", verifoof);
try {
if (!password) {
- throw new Error("Le mot de passe est obligatoire et ne peut être indéfini");
+ throw new Error("Le mot de passe est obligatoire et ne peut être indéfini");
}
+ if (!verifoof) {
+ throw new Error("Le nom du chien doit être défini" );
+ }
+ if (!registerVerification()) {
+ console.log("Invalid dog name:", verifoof);
+ return res.status(201).json({ message: "Mauvais nom de chien" });
+ }
+
+ const existingUser = await User.findOne({ email });
+ if (existingUser) {
+ return res.status(201).json({ message: "L'email existe déjà, veuillez en choisir un autre." });
+ }
+
+ // Hash password and create user
const hashedPassword = await bcrypt.hash(password, 10);
const user = new User({ name, email, password: hashedPassword, role });
await user.save();
@@ -165,6 +172,7 @@ router.post("/register", async (req, res) => {
res.status(201).json({ message: "L'utilisateur s'est enregistré avec succès !" });
} catch (err) {
res.status(400).json({ error: err.message });
+ res.status(403).json({ message: "Erreur interne lmao" });
}
});