This commit is contained in:
Kasper Rynning-Tønnesen
2020-01-17 16:32:56 +01:00
parent 002cf71137
commit 9b4f770ac6
3 changed files with 65 additions and 21 deletions

View File

@@ -4,11 +4,16 @@ const User = require(path.join(__dirname + "/../schemas/User"));
const router = require("express").Router(); const router = require("express").Router();
router.get("/", function(req, res) { router.get("/", function(req, res) {
res.render("index", { user: req.user }); console.log("here", req.isAuthenticated());
if (!req.isAuthenticated()) {
res.sendFile(path.join(__dirname + "/../public/login.html"));
return;
}
res.sendFile(path.join(__dirname + "/../public/index.html"));
}); });
router.get("/register", function(req, res) { router.get("/register", function(req, res) {
res.render("register", {}); res.sendFile(path.join(__dirname + "/../public/register.html"));
}); });
router.post("/register", function(req, res, next) { router.post("/register", function(req, res, next) {
@@ -30,14 +35,13 @@ router.post("/register", function(req, res, next) {
}); });
router.get("/login", function(req, res) { router.get("/login", function(req, res) {
res.render("login", { user: req.user, message: req.flash("error") }); res.sendFile(path.join(__dirname + "/../public/login.html"));
}); });
router.post( router.post(
"/login", "/login",
passport.authenticate("local", { passport.authenticate("local", {
failureRedirect: "/login", failureRedirect: "/login"
failureFlash: true
}), }),
function(req, res) { function(req, res) {
res.redirect("/"); res.redirect("/");

View File

@@ -1,15 +1,59 @@
<html> <html>
<head> <head>
<title>Vinlottis</title> <title>Vinlottis</title>
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet"> <link
</head> href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
<body> rel="stylesheet"
<h1>Official vin lottis homepage</h1> />
</body> </head>
<body>
<h1>Official vin lottis homepage</h1>
<code id="purchase"></code>
<code id="wines"></code>
<code id="colors"></code>
<code id="highscores"></code>
<style> <script>
body { (async function() {
font-family: 'Roboto', sans-serif; var _purchase = await fetch("/api/purchase/statistics");
} var purchase = await _purchase.json();
</style>
var _wines = await fetch("/api/wines/statistics");
var wines = await _wines.json();
var _colors = await fetch("/api/purchase/statistics/color");
var color = await _colors.json();
var _highscores = await fetch("/api/highscore/statistics");
var highscore = await _highscores.json();
document.getElementById("purchase").innerHTML = JSON.stringify(
purchase,
null,
2
);
document.getElementById("wines").innerHTML = JSON.stringify(
wines,
null,
2
);
document.getElementById("colors").innerHTML = JSON.stringify(
color,
null,
2
);
document.getElementById("highscores").innerHTML = JSON.stringify(
highscore,
null,
2
);
})();
</script>
</body>
<style>
body {
font-family: "Roboto", sans-serif;
}
</style>
</html> </html>

View File

@@ -41,10 +41,6 @@ passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser()); passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser()); passport.deserializeUser(User.deserializeUser());
app.get("/", function(req, res) {
res.sendFile(path.join(__dirname + "/public/index.html"));
});
app.use("/", loginApi); app.use("/", loginApi);
app.use("/api/", updateApi); app.use("/api/", updateApi);
app.use("/api/", retrieveApi); app.use("/api/", retrieveApi);