Update to login routes
This commit is contained in:
@@ -75,9 +75,9 @@
|
|||||||
{{#each topScorers.scorers}}
|
{{#each topScorers.scorers}}
|
||||||
<tr id="top-scorers-row">
|
<tr id="top-scorers-row">
|
||||||
<td id="league-top-scorers-goals-column">{{goals}}</td>
|
<td id="league-top-scorers-goals-column">{{goals}}</td>
|
||||||
<td><img id="league-top-scorers-logo" clubID="{{team.team_id}}" src="{{team.team_crest}}" alt="{{table.team_name}} Crest"></img></td>
|
<td><img id="league-top-scorers-logo" href="/club/{{team.team_id}}" src="{{team.team_crest}}" alt="{{table.team_name}} Crest"></img></td>
|
||||||
<td id="league-top-scorers-player-name-column">{{player.player_name}}</td>
|
<td id="league-top-scorers-player-name-column">{{player.player_name}}</td>
|
||||||
<td id="league-top-scorers-club-name-column" clubID="{{team.team_id}}">{{team.team_name}}</td>
|
<td id="league-top-scorers-club-name-column" href="/club/{{team.team_id}}">{{team.team_name}}</td>
|
||||||
<td>{{games_played}}</td>
|
<td>{{games_played}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
20
src/app.js
20
src/app.js
@@ -58,23 +58,9 @@ app.use(fetchMatchesData);
|
|||||||
const convert_time = require("./middleware/navigation-bar/convert-time");
|
const convert_time = require("./middleware/navigation-bar/convert-time");
|
||||||
app.use(convert_time);
|
app.use(convert_time);
|
||||||
|
|
||||||
// Leagues Page Middleware
|
// Other middleware and route imports
|
||||||
|
const leagueRoutes = require("./routes/league-pages/league-routes");
|
||||||
const fetchLeaguesData = require("./middleware/leagues-page/get-current-league-information");
|
leagueRoutes(app);
|
||||||
const fetchLeagueScorerData = require("./middleware/leagues-page/get-current-league-top-scorers");
|
|
||||||
|
|
||||||
app.get(
|
|
||||||
"/league/:leagueID",
|
|
||||||
[fetchLeaguesData, fetchLeagueScorerData],
|
|
||||||
(req, res) => {
|
|
||||||
// Render the Handlebars view with league data
|
|
||||||
res.render("pages/leagues-page", {
|
|
||||||
leagueID: req.params.leagueID,
|
|
||||||
leagues: res.locals.leagues,
|
|
||||||
scorers: res.locals.topScorers, // Assuming fetchLeagueScorerData sets the data in res.locals.scorers
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Clubs Page Middleware
|
// Clubs Page Middleware
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ router.post("/login", async (req, res) => {
|
|||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// Redirect user to login screen if no user is found with the provided username
|
// Redirect user to login screen if no user is found with the provided username
|
||||||
return res.redirect("/register");
|
return res.render("pages/home", { message: "User Not Found!" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if password from request matches with password in DB
|
// Check if password from request matches with password in DB
|
||||||
@@ -28,7 +28,7 @@ router.post("/login", async (req, res) => {
|
|||||||
// Check if match returns no data
|
// Check if match returns no data
|
||||||
if (!match) {
|
if (!match) {
|
||||||
// Render the login page with the message parameter
|
// Render the login page with the message parameter
|
||||||
return res.render("/", { message: "Password does not match" });
|
return res.render("pages/home", { message: "Password does not match" });
|
||||||
} else {
|
} else {
|
||||||
// Save user information in the session variable
|
// Save user information in the session variable
|
||||||
req.session.user = user;
|
req.session.user = user;
|
||||||
|
|||||||
25
src/routes/league-pages/league-routes.js
Normal file
25
src/routes/league-pages/league-routes.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// src/routes/leagueRoutes.js
|
||||||
|
const express = require("express");
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
// Import the middleware functions
|
||||||
|
const fetchLeaguesData = require("../../middleware/leagues-page/get-current-league-information");
|
||||||
|
const fetchLeagueScorerData = require("../../middleware/leagues-page/get-current-league-top-scorers");
|
||||||
|
|
||||||
|
// Define the route handling function
|
||||||
|
const leagueRoutes = (app) => {
|
||||||
|
app.get(
|
||||||
|
"/league/:leagueID",
|
||||||
|
[fetchLeaguesData, fetchLeagueScorerData],
|
||||||
|
(req, res) => {
|
||||||
|
// Render the Handlebars view with league data
|
||||||
|
res.render("pages/leagues-page", {
|
||||||
|
leagueID: req.params.leagueID,
|
||||||
|
leagues: res.locals.leagues,
|
||||||
|
scorers: res.locals.topScorers, // Assuming fetchLeagueScorerData sets the data in res.locals.scorers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = leagueRoutes;
|
||||||
Reference in New Issue
Block a user