From 767fc17c8415fc647a6b6d2aa7bbc51ae5e0d384 Mon Sep 17 00:00:00 2001
From: proyectomarco
Date: Fri, 4 Nov 2022 17:49:44 +0100
Subject: [PATCH 01/11] routes done
---
Project/config/index.js | 15 +++++++++++----
Project/models/User.model.js | 2 +-
Project/routes/auth.routes.js | 16 +++++++---------
Project/routes/index.routes.js | 12 ++++++++++++
Project/views/auth/login.hbs | 6 +++---
Project/views/index.hbs | 4 +++-
Project/views/restaurants/restaurant-list.hbs | 1 +
Project/views/user/profile.hbs | 4 ++++
8 files changed, 42 insertions(+), 18 deletions(-)
create mode 100644 Project/views/restaurants/restaurant-list.hbs
create mode 100644 Project/views/user/profile.hbs
diff --git a/Project/config/index.js b/Project/config/index.js
index 81ca4e4..a95486c 100644
--- a/Project/config/index.js
+++ b/Project/config/index.js
@@ -51,15 +51,22 @@ module.exports = (app) => {
favicon(path.join(__dirname, "..", "public", "images", "favicon.ico"))
);
+
// âšī¸ Middleware that adds a "req.session" information and later to check that you are who you say you are đ
app.use(
session({
- secret: process.env.SESSION_SECRET || "super hyper secret key",
+ secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
+ cookie: {
+ sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
+ secure: process.env.NODE_ENV === 'production',
+ httpOnly: true,
+ maxAge: 60000
+ },
store: MongoStore.create({
- mongoUrl: MONGO_URI,
- }),
- })
+ mongoUrl: process.env.MONGODB_URI || 'mongodb://localhost:27017/project2'
+ })
+ })
);
};
diff --git a/Project/models/User.model.js b/Project/models/User.model.js
index 0dacd5d..46738dc 100644
--- a/Project/models/User.model.js
+++ b/Project/models/User.model.js
@@ -5,7 +5,7 @@ const userSchema = new Schema(
{
username: {
type: String,
- required: false,
+ required: true,
unique: true,
trim: true,
},
diff --git a/Project/routes/auth.routes.js b/Project/routes/auth.routes.js
index 474cb56..c22d486 100644
--- a/Project/routes/auth.routes.js
+++ b/Project/routes/auth.routes.js
@@ -14,6 +14,7 @@ const User = require("../models/User.model");
// Require necessary (isLoggedOut and isLiggedIn) middleware in order to control access to specific routes
const isLoggedOut = require("../middleware/isLoggedOut");
const isLoggedIn = require("../middleware/isLoggedIn");
+const { response } = require("express");
// GET /auth/signup
router.get("/signup", isLoggedOut, (req, res) => {
@@ -134,22 +135,19 @@ router.post("/login", isLoggedOut, (req, res, next) => {
// Remove the password field
delete req.session.currentUser.password;
- res.redirect("/");
+ res.redirect("/restaurants");
})
.catch((err) => next(err)); // In this case, we send error handling to the error handling middleware.
})
.catch((err) => next(err));
});
-// GET /auth/logout
-router.get("/logout", isLoggedIn, (req, res) => {
- req.session.destroy((err) => {
- if (err) {
- res.status(500).render("auth/logout", { errorMessage: err.message });
- return;
- }
- res.redirect("/");
+
+router.post('/logout', (req, res, next) => {
+ req.session.destroy(err => {
+ if (err) next(err);
+ res.redirect('/');
});
});
diff --git a/Project/routes/index.routes.js b/Project/routes/index.routes.js
index f538ffe..df329e5 100644
--- a/Project/routes/index.routes.js
+++ b/Project/routes/index.routes.js
@@ -1,4 +1,5 @@
const express = require('express');
+const isLoggedIn = require('../middleware/isLoggedIn');
const router = express.Router();
/* GET home page */
@@ -6,4 +7,15 @@ router.get("/", (req, res, next) => {
res.render("index");
});
+
+// GET // User Profile
+router.get('/profile', isLoggedIn, (req, res) => {
+ res.render('user/profile')
+})
+
+router.get('/restaurants', (req, res) => {
+ res.render('restaurants/restaurant-list')
+})
+
+
module.exports = router;
diff --git a/Project/views/auth/login.hbs b/Project/views/auth/login.hbs
index 0d33b08..3506b3c 100644
--- a/Project/views/auth/login.hbs
+++ b/Project/views/auth/login.hbs
@@ -2,15 +2,15 @@
Log In
+ {{this.address}}
+ {{this.phonenumber}}
+ {{this.price}}
+ {{this.wifi}}
+ {{this.coworking}}
+ {{this.delivery}}
+ {{this.instagram}}
+
+ {{/each}}
+
+
diff --git a/Project/views/restaurants/restaurantCard.hbs b/Project/views/restaurants/restaurantCard.hbs
new file mode 100644
index 0000000..d80e749
--- /dev/null
+++ b/Project/views/restaurants/restaurantCard.hbs
@@ -0,0 +1,12 @@
+{{#each restaurantCard}}
+
{{this.style}}
+ {{this.address}}
+ {{this.phonenumber}}
+ {{this.price}}
+ {{this.wifi}}
+ {{this.coworking}}
+ {{this.delivery}}
+ {{this.instagram}}
+
+ {{/each}}