From 8b5463cd0340ad3f73e50e319ed832fcb435a285 Mon Sep 17 00:00:00 2001 From: MatzJeurissen <84962321+MatzJeurissen@users.noreply.github.com> Date: Wed, 22 Mar 2023 22:48:19 +0100 Subject: [PATCH] f --- app.js | 16 +- node_modules/.package-lock.json | 13 + package-lock.json | 27 ++ package.json | 1 + public/css/styles.css | 383 +++++++++++++++---------- server/controllers/authController.js | 78 ++++- server/controllers/recipeController.js | 18 +- server/controllers/userController.js | 99 +++++++ server/models/User.js | 5 +- server/roles.js | 20 ++ server/routes/authRoutes.js | 36 ++- server/routes/recipeRoutes.js | 5 +- views/admin.ejs | 32 ++- views/homeAdmin.ejs | 181 ++++++++++++ views/layouts/main.ejs | 136 ++++++++- 15 files changed, 845 insertions(+), 205 deletions(-) create mode 100644 server/controllers/userController.js create mode 100644 server/roles.js create mode 100644 views/homeAdmin.ejs diff --git a/app.js b/app.js index 7caf845f..867ef8b3 100644 --- a/app.js +++ b/app.js @@ -101,7 +101,7 @@ const session = require('express-session'); const cookieParser = require('cookie-parser'); const flash = require('connect-flash'); const bodyParser = require("body-parser"); -const { adminAuth, userAuth } = require("./middleware/auth.js"); +// const { adminAuth, userAuth } = require("./middleware/auth.js"); const connectDB = require("./db"); const app = express(); @@ -130,21 +130,21 @@ app.set('view engine', 'ejs'); const routes = require('./server/routes/recipeRoutes.js') app.use('/', routes); -// const authRoutes= require('./server/routes/recipeRoutes.js') -// app.use('/', authRoutes); +const authRoutes= require('./server/routes/authRoutes.js') +app.use('/', authRoutes); connectDB(); // Routes app.use("/api/auth", require("./Auth/route")); -app.get("/", (req, res) => res.render("home")); -app.get("/register", (req, res) => res.render("register")); -app.get("/login", (req, res) => res.render("login")); +// app.get("/", (req, res) => res.render("home")); +// app.get("/register", (req, res) => res.render("register")); +// app.get("/login", (req, res) => res.render("login")); app.get("/logout", (req, res) => { res.cookie("jwt", "", { maxAge: "1" }); res.redirect("/"); }); -app.get("/admin", adminAuth, (req, res) => res.render("admin")); -app.get("/basic", userAuth, (req, res) => res.render("user")); +// app.get("/admin", adminAuth, (req, res) => res.render("admin")); +// app.get("/basic", userAuth, (req, res) => res.render("user")); app.listen(port, ()=> console.log(`Listening to port ${port}`)); diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 5ead795f..0a6fe0b6 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -6366,6 +6366,14 @@ "node": ">= 0.6" } }, + "node_modules/accesscontrol": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/accesscontrol/-/accesscontrol-2.2.1.tgz", + "integrity": "sha512-52EvFk/J9EF+w4mYQoKnOTkEMj01R1U5n2fc1dai6x1xkgOks3DGkx01qQL2cKFxGmE4Tn1krAU3jJA9L1NMkg==", + "dependencies": { + "notation": "^1.3.6" + } + }, "node_modules/acorn": { "version": "8.8.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", @@ -9864,6 +9872,11 @@ "node": ">=8" } }, + "node_modules/notation": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/notation/-/notation-1.3.6.tgz", + "integrity": "sha512-DIuJmrP/Gg1DcXKaApsqcjsJD6jEccqKSfmU3BUx/f1GHsMiTJh70cERwYc64tOmTRTARCeMwkqNNzjh3AHhiw==" + }, "node_modules/npm-run-path": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", diff --git a/package-lock.json b/package-lock.json index 38fe302c..8ca5ea12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "accesscontrol": "^2.2.1", "bcrypt": "^5.1.0", "bcryptjs": "^2.4.3", "body-parser": "^1.20.2", @@ -6408,6 +6409,14 @@ "node": ">= 0.6" } }, + "node_modules/accesscontrol": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/accesscontrol/-/accesscontrol-2.2.1.tgz", + "integrity": "sha512-52EvFk/J9EF+w4mYQoKnOTkEMj01R1U5n2fc1dai6x1xkgOks3DGkx01qQL2cKFxGmE4Tn1krAU3jJA9L1NMkg==", + "dependencies": { + "notation": "^1.3.6" + } + }, "node_modules/acorn": { "version": "8.8.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", @@ -9942,6 +9951,11 @@ "node": ">=8" } }, + "node_modules/notation": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/notation/-/notation-1.3.6.tgz", + "integrity": "sha512-DIuJmrP/Gg1DcXKaApsqcjsJD6jEccqKSfmU3BUx/f1GHsMiTJh70cERwYc64tOmTRTARCeMwkqNNzjh3AHhiw==" + }, "node_modules/npm-run-path": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", @@ -16677,6 +16691,14 @@ "negotiator": "0.6.3" } }, + "accesscontrol": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/accesscontrol/-/accesscontrol-2.2.1.tgz", + "integrity": "sha512-52EvFk/J9EF+w4mYQoKnOTkEMj01R1U5n2fc1dai6x1xkgOks3DGkx01qQL2cKFxGmE4Tn1krAU3jJA9L1NMkg==", + "requires": { + "notation": "^1.3.6" + } + }, "acorn": { "version": "8.8.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", @@ -19344,6 +19366,11 @@ "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", "integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==" }, + "notation": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/notation/-/notation-1.3.6.tgz", + "integrity": "sha512-DIuJmrP/Gg1DcXKaApsqcjsJD6jEccqKSfmU3BUx/f1GHsMiTJh70cERwYc64tOmTRTARCeMwkqNNzjh3AHhiw==" + }, "npm-run-path": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", diff --git a/package.json b/package.json index 5a0483e9..f16f320f 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "", "license": "ISC", "dependencies": { + "accesscontrol": "^2.2.1", "bcrypt": "^5.1.0", "bcryptjs": "^2.4.3", "body-parser": "^1.20.2", diff --git a/public/css/styles.css b/public/css/styles.css index 93a216a9..8acdf769 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -44,166 +44,249 @@ a { color: var(--bs-dark); } object-fit: cover; } -.site-footer -{ - background-color:#26272b; - padding:45px 0 20px; - font-size:15px; - line-height:24px; - color:#737373; -} -.site-footer hr -{ - border-top-color:#bbb; - opacity:0.5 -} -.site-footer hr.small -{ - margin:20px 0 -} -.site-footer h6 -{ - color:#fff; - font-size:16px; - text-transform:uppercase; - margin-top:5px; - letter-spacing:2px -} -.site-footer a -{ - color:#737373; -} -.site-footer a:hover -{ - color:#3366cc; - text-decoration:none; -} -.footer-links -{ - padding-left:0; - list-style:none +.footer-basic { + padding:40px 0; + background-color:#ffffff; + color:#4b4c4d; + margin-top: 80px; + border-top: 1px solid lightslategrey; } -.footer-links li -{ - display:block + +.footer-basic ul { + padding:0; + list-style:none; + text-align:center; + font-size:18px; + line-height:1.6; + margin-bottom:0; } -.footer-links a -{ - color:#737373 + +.footer-basic li { + padding:0 10px; } -.footer-links a:active,.footer-links a:focus,.footer-links a:hover -{ - color:#3366cc; + +.footer-basic ul a { + color:inherit; text-decoration:none; + opacity:0.8; } -.footer-links.inline li -{ - display:inline-block + +.footer-basic ul a:hover { + opacity:1; } -.site-footer .social-icons -{ - text-align:right + +.footer-basic .social { + text-align:center; + padding-bottom:25px; } -.site-footer .social-icons a -{ + +.footer-basic .social > a { + font-size:24px; width:40px; height:40px; line-height:40px; - margin-left:6px; - margin-right:0; - border-radius:100%; - background-color:#33353d -} -.copyright-text -{ - margin:0 -} -@media (max-width:991px) -{ - .site-footer [class^=col-] - { - margin-bottom:30px - } -} -@media (max-width:767px) -{ - .site-footer - { - padding-bottom:0 - } - .site-footer .copyright-text,.site-footer .social-icons - { - text-align:center - } -} -.social-icons -{ - padding-left:0; - margin-bottom:0; - list-style:none -} -.social-icons li -{ - display:inline-block; - margin-bottom:4px -} -.social-icons li.title -{ - margin-right:15px; - text-transform:uppercase; - color:#96a2b2; - font-weight:700; - font-size:13px -} -.social-icons a{ - background-color:#eceeef; - color:#818a91; - font-size:16px; display:inline-block; - line-height:44px; - width:44px; - height:44px; text-align:center; - margin-right:8px; - border-radius:100%; - -webkit-transition:all .2s linear; - -o-transition:all .2s linear; - transition:all .2s linear -} -.social-icons a:active,.social-icons a:focus,.social-icons a:hover -{ - color:#fff; - background-color:#29aafe -} -.social-icons.size-sm a -{ - line-height:34px; - height:34px; - width:34px; - font-size:14px -} -.social-icons a.facebook:hover -{ - background-color:#3b5998 -} -.social-icons a.twitter:hover -{ - background-color:#00aced -} -.social-icons a.linkedin:hover -{ - background-color:#007bb6 -} -.social-icons a.dribbble:hover -{ - background-color:#ea4c89 -} -@media (max-width:767px) -{ - .social-icons li.title - { - display:block; - margin-right:0; - font-weight:600 - } + border-radius:50%; + border:1px solid #ccc; + margin:0 8px; + color:inherit; + opacity:0.75; +} + +.footer-basic .social > a:hover { + opacity:0.9; } + +.footer-basic .copyright { + margin-top:15px; + text-align:center; + font-size:13px; + color:#aaa; + margin-bottom:0; +} + + + +.form-control { + box-shadow: none; + font-weight: normal; + font-size: 13px; +} +.navbar { + background: #fff; + padding-left: 16px; + padding-right: 16px; + border-bottom: 1px solid #dfe3e8; + border-radius: 0; +} +.nav-link img { + border-radius: 50%; + width: 36px; + height: 36px; + margin: -8px 0; + float: left; + margin-right: 10px; +} +.navbar .navbar-brand { + padding-left: 0; + font-size: 20px; + padding-right: 50px; +} +.navbar .navbar-brand b { + color: #33cabb; +} +.navbar .form-inline { + display: inline-block; +} +.navbar a { + color: #fff; + font-size: 15px; +} +.search-box { + position: relative; +} +.search-box input { + padding-right: 35px; + border-color: #dfe3e8; + border-radius: 4px !important; + box-shadow: none +} +.search-box .input-group-text { + min-width: 35px; + border: none; + background: transparent; + position: absolute; + right: 0; + z-index: 9; + padding: 7px; + height: 100%; +} +.search-box i { + color: #a0a5b1; + font-size: 19px; +} +.navbar .sign-up-btn { + min-width: 110px; + max-height: 36px; +} +.navbar .dropdown-menu { + color: #999; + font-weight: normal; + border-radius: 1px; + border-color: #e5e5e5; + box-shadow: 0 2px 8px rgba(0,0,0,.05); +} +.navbar a, .navbar a:active { + color: #888; + padding: 8px 20px; + background: transparent; + line-height: normal; +} +.navbar .navbar-form { + border: none; +} +.navbar .action-form { + width: 280px; + padding: 20px; + left: auto; + right: 0; + font-size: 14px; +} +.navbar .action-form a { + color: #33cabb; + padding: 0 !important; + font-size: 14px; +} +.navbar .action-form .hint-text { + text-align: center; + margin-bottom: 15px; + font-size: 13px; +} +.navbar .btn-primary, .navbar .btn-primary:active { + color: #fff; + background: #33cabb !important; + border: none; +} +.navbar .btn-primary:hover, .navbar .btn-primary:focus { + color: #fff; + background: #31bfb1 !important; +} +.navbar .social-btn .btn, .navbar .social-btn .btn:hover { + color: #fff; + margin: 0; + padding: 0 !important; + font-size: 13px; + border: none; + transition: all 0.4s; + text-align: center; + line-height: 34px; + width: 47%; + text-decoration: none; +} +.navbar .social-btn .facebook-btn { + background: #507cc0; +} +.navbar .social-btn .facebook-btn:hover { + background: #4676bd; +} +.navbar .social-btn .twitter-btn { + background: #64ccf1; +} +.navbar .social-btn .twitter-btn:hover { + background: #4ec7ef; +} +.navbar .social-btn .btn i { + margin-right: 5px; + font-size: 16px; + position: relative; + top: 2px; +} +.or-seperator { + margin-top: 32px; + text-align: center; + border-top: 1px solid #e0e0e0; +} +.or-seperator b { + color: #666; + padding: 0 8px; + width: 30px; + height: 30px; + font-size: 13px; + text-align: center; + line-height: 26px; + background: #fff; + display: inline-block; + border: 1px solid #e0e0e0; + border-radius: 50%; + position: relative; + top: -15px; + z-index: 1; +} +.navbar .action-buttons .dropdown-toggle::after { + display: none; +} +.form-check-label input { + position: relative; + top: 1px; +} +@media (min-width: 1200px){ + .form-inline .input-group { + width: 300px; + margin-left: 30px; + } +} +@media (max-width: 768px){ + .navbar .dropdown-menu.action-form { + width: 100%; + padding: 10px 15px; + background: transparent; + border: none; + } + .navbar .form-inline { + display: block; + } + .navbar .input-group { + width: 100%; + } +} \ No newline at end of file diff --git a/server/controllers/authController.js b/server/controllers/authController.js index 62788123..704af279 100644 --- a/server/controllers/authController.js +++ b/server/controllers/authController.js @@ -1,10 +1,74 @@ -require('../models/database'); -const Category = require('../models/User'); +// require('../models/database'); +const User = require('../models/User'); +exports.about = async(req, res) => { + try { + res.render("home"); + } catch (error) { + res.status(500).send({message: error.message || "Error Occured" }); + } + } +exports.register = async(req, res) => { + try { + res.render("register"); + } catch (error) { + res.status(500).send({message: error.message || "Error Occured" }); + } +} -exports.authUser = async(req, res) => { - const infoErrorsObj = req.flash('infoErrors'); - const infoSubmitObj = req.flash('infoSubmit'); - res.render('submit-recipe', { title: 'Cooking Blog - Submit Recipe', infoErrorsObj, infoSubmitObj } ); -} \ No newline at end of file +exports.login = async(req, res) => { + try { + res.render("login"); + } catch (error) { + res.status(500).send({message: error.message || "Error Occured" }); + } +} + +exports.logout = async(req, res) => { + try { + (req, res) => { + res.cookie("jwt", "", { maxAge: "1" }); + res.redirect("/"); + }; + } catch (error) { + res.status(500).send({message: error.message || "Error Occured" }); + } +} + +exports.admin = async(req, res) => { + try { + const limitNumber = 5; + const users = await User.find({}).limit(limitNumber); + res.render("admin", {users}); + } catch (error) { + res.status(500).send({message: error.message || "Error Occured" }); + } +} + +// exports.getUsers = async (req, res, next) => { +// await User.find({}) +// .then((users) => { +// const userFunction = users.map((user) => { +// const container = {}; +// container.username = user.username; +// container.role = user.role; +// container.id = user._id; + +// return container; +// }); +// res.status(200).json({ user: userFunction }); +// }) +// .catch((err) => +// res.status(401).json({ message: "Not successful", error: err.message }) +// ); +// }; + + +exports.basic = async(req, res) => { + try { + res.render("basic"); + } catch (error) { + res.status(500).send({message: error.message || "Error Occured" }); + } +} diff --git a/server/controllers/recipeController.js b/server/controllers/recipeController.js index a7285aee..516efaa8 100644 --- a/server/controllers/recipeController.js +++ b/server/controllers/recipeController.js @@ -1,4 +1,6 @@ require('../models/database'); +// const { adminAuth, userAuth } = require("./server/middleware/auth.js"); + const Category = require('../models/Category'); const Recipe = require('../models/Recipe'); @@ -19,7 +21,7 @@ exports.homepage = async(req, res) => { res.render('index', { title: 'Cooking Blog - Home', categories, food } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -33,7 +35,7 @@ exports.exploreCategories = async(req, res) => { const categories = await Category.find({}).limit(limitNumber); res.render('categories', { title: 'Cooking Blog - Categoreis', categories } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -49,7 +51,7 @@ exports.exploreCategoriesById = async(req, res) => { const categoryById = await Recipe.find({ 'category': categoryId }).limit(limitNumber); res.render('categories', { title: 'Cooking Blog - Categoreis', categoryById } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -63,7 +65,7 @@ exports.exploreRecipe = async(req, res) => { const recipe = await Recipe.findById(recipeId); res.render('recipe', { title: 'Cooking Blog - Recipe', recipe } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -78,7 +80,7 @@ exports.searchRecipe = async(req, res) => { let recipe = await Recipe.find( { $text: { $search: searchTerm, $diacriticSensitive: true } }); res.render('search', { title: 'Cooking Blog - Search', recipe } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -93,7 +95,7 @@ exports.exploreLatest = async(req, res) => { const recipe = await Recipe.find({}).sort({ _id: -1 }).limit(limitNumber); res.render('explore-latest', { title: 'Cooking Blog - Explore Latest', recipe } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -110,7 +112,7 @@ exports.exploreRandom = async(req, res) => { let recipe = await Recipe.findOne().skip(random).exec(); res.render('explore-random', { title: 'Cooking Blog - Explore Latest', recipe } ); } catch (error) { - res.satus(500).send({message: error.message || "Error Occured" }); + res.status(500).send({message: error.message || "Error Occured" }); } } @@ -146,7 +148,7 @@ exports.submitRecipeOnPost = async(req, res) => { uploadPath = require('path').resolve('./') + '/public/uploads/' + newImageName; imageUploadFile.mv(uploadPath, function(err){ - if(err) return res.satus(500).send(err); + if(err) return res.status(500).send(err); }) } diff --git a/server/controllers/userController.js b/server/controllers/userController.js new file mode 100644 index 00000000..20f2d054 --- /dev/null +++ b/server/controllers/userController.js @@ -0,0 +1,99 @@ +const User = require('../models/User'); +const jwt = require('jsonwebtoken'); +const bcrypt = require('bcrypt'); + +async function hashPassword(password) { + return await bcrypt.hash(password, 10); +} + +async function validatePassword(plainPassword, hashedPassword) { + return await bcrypt.compare(plainPassword, hashedPassword); +} + +exports.signup = async (req, res, next) => { + try { + const { email, password, role } = req.body + const hashedPassword = await hashPassword(password); + const newUser = new User({ email, password: hashedPassword, role: role || "basic" }); + const accessToken = jwt.sign({ userId: newUser._id }, process.env.JWT_SECRET, { + expiresIn: "1d" + }); + newUser.accessToken = accessToken; + await newUser.save(); + res.json({ + data: newUser, + accessToken + }) + } catch (error) { + next(error) + } +} + +exports.login = async (req, res, next) => { + try { + const { email, password } = req.body; + const user = await User.findOne({ email }); + if (!user) return next(new Error('Email does not exist')); + const validPassword = await validatePassword(password, user.password); + if (!validPassword) return next(new Error('Password is not correct')) + const accessToken = jwt.sign({ userId: user._id }, process.env.JWT_SECRET, { + expiresIn: "1d" + }); + await User.findByIdAndUpdate(user._id, { accessToken }) + res.status(200).json({ + data: { email: user.email, role: user.role }, + accessToken + }) + } catch (error) { + next(error); + } + } + + exports.getUsers = async (req, res, next) => { + const users = await User.find({}); + res.status(200).json({ + data: users + }); + } + + exports.getUser = async (req, res, next) => { + try { + const userId = req.params.userId; + const user = await User.findById(userId); + if (!user) return next(new Error('User does not exist')); + res.status(200).json({ + data: user + }); + } catch (error) { + next(error) + } + } + + exports.updateUser = async (req, res, next) => { + try { + const update = req.body + const userId = req.params.userId; + await User.findByIdAndUpdate(userId, update); + const user = await User.findById(userId) + res.status(200).json({ + data: user, + message: 'User has been updated' + }); + } catch (error) { + next(error) + } + } + + exports.deleteUser = async (req, res, next) => { + try { + const userId = req.params.userId; + await User.findByIdAndDelete(userId); + res.status(200).json({ + data: null, + message: 'User has been deleted' + }); + } catch (error) { + next(error) + } + } + \ No newline at end of file diff --git a/server/models/User.js b/server/models/User.js index 87168adb..c62a5d96 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -16,7 +16,10 @@ const UserSchema = new Mongoose.Schema({ default: "Basic", required: true, }, -}) + accessToken: { + type: String + } + }); const User = Mongoose.model("user", UserSchema) module.exports = User \ No newline at end of file diff --git a/server/roles.js b/server/roles.js new file mode 100644 index 00000000..7fd84236 --- /dev/null +++ b/server/roles.js @@ -0,0 +1,20 @@ +const AccessControl = require("accesscontrol"); +const ac = new AccessControl(); + +exports.roles = (function() { +ac.grant("basic") + .readOwn("profile") + .updateOwn("profile") + +ac.grant("supervisor") + .extend("basic") + .readAny("profile") + +ac.grant("admin") + .extend("basic") + .extend("supervisor") + .updateAny("profile") + .deleteAny("profile") + +return ac; +})(); \ No newline at end of file diff --git a/server/routes/authRoutes.js b/server/routes/authRoutes.js index 9da75a61..53a13f34 100644 --- a/server/routes/authRoutes.js +++ b/server/routes/authRoutes.js @@ -1,21 +1,31 @@ // routes/userRoutes.js -const express = require("express"); -const User = require("../models/userModel"); -const bcrypt = require("bcrypt"); - +const express = require('express'); +const { adminAuth, userAuth } = require('../../middleware/auth'); const router = express.Router(); +const authController = require('../controllers/authController'); /** * App Routes */ -// router.get('/', recipeController.homepage); -// router.get('/recipe/:id', recipeController.exploreRecipe ); -// router.get('/categories', recipeController.exploreCategories); -// router.get('/categories/:id', recipeController.exploreCategoriesById); -// router.post('/search', recipeController.searchRecipe); -// router.get('/explore-latest', recipeController.exploreLatest); -// router.get('/explore-random', recipeController.exploreRandom); -// router.get('/submit-recipe', recipeController.submitRecipe); -// router.post('/submit-recipe', recipeController.submitRecipeOnPost); +router.get('/about"', authController.about); +router.get('/register', authController.register); +router.get('/login', authController.login); +router.get('/logout', authController.logout); +router.get('/admin', adminAuth, authController.admin); +router.get('/basic', userAuth, authController.basic); +router.get('/basic', userAuth, authController.basic); + + + + +// app.get("/about", (req, res) => res.render("home")); +// app.get("/register", (req, res) => res.render("register")); +// app.get("/login", (req, res) => res.render("login")); +// app.get("/logout", (req, res) => { +// res.cookie("jwt", "", { maxAge: "1" }); +// res.redirect("/"); +// }); +// app.get("/admin", adminAuth, (req, res) => res.render("admin")); +// app.get("/basic", userAuth, (req, res) => res.render("user")); module.exports = router; \ No newline at end of file diff --git a/server/routes/recipeRoutes.js b/server/routes/recipeRoutes.js index 01666fda..f0cfdc45 100644 --- a/server/routes/recipeRoutes.js +++ b/server/routes/recipeRoutes.js @@ -1,6 +1,7 @@ const express = require('express'); const router = express.Router(); const recipeController = require('../controllers/recipeController'); +const { adminAuth, userAuth } = require('../../middleware/auth'); /** * App Routes @@ -12,8 +13,8 @@ router.get('/categories/:id', recipeController.exploreCategoriesById); router.post('/search', recipeController.searchRecipe); router.get('/explore-latest', recipeController.exploreLatest); router.get('/explore-random', recipeController.exploreRandom); -router.get('/submit-recipe', recipeController.submitRecipe); -router.post('/submit-recipe', recipeController.submitRecipeOnPost); +router.get('/submit-recipe', adminAuth, recipeController.submitRecipe); +router.post('/submit-recipe', adminAuth, recipeController.submitRecipeOnPost); module.exports = router; \ No newline at end of file diff --git a/views/admin.ejs b/views/admin.ejs index 3f0be784..4fd496e7 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -1,4 +1,4 @@ - + -
+