Skip to content

Commit

Permalink
Merge pull request #14 from helloitsrufio/revert-11-master
Browse files Browse the repository at this point in the history
Revert "Add input link to navbar with check for admin user, for issue #9"
  • Loading branch information
helloitsrufio authored Mar 4, 2024
2 parents f5b276f + b20a694 commit fdf7747
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 72 deletions.
13 changes: 5 additions & 8 deletions controllers/about.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const { isAdmin } = require("../middleware/auth");
module.exports = {
//About Page: app.get('/about')
about: async (req, res) => {
res.render("aboutPage.ejs", {
admin: isAdmin(req?.user?.email),
});
},
};
//About Page: app.get('/about')
about: async (req,res) => {
res.render('aboutPage.ejs')
}
}
19 changes: 7 additions & 12 deletions controllers/alphabet.controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
const { isAdmin } = require("../middleware/auth");

module.exports = {
//Alphabet Page app.get('/alphabet'),
alphabet: async (req, res) => {
try {
res.render("alphabetPage.ejs", {
admin: isAdmin(req?.user?.email),
});
} catch (err) {
console.error(err);
//Alphabet Page app.get('/alphabet'),
alphabet: async (req,res)=>{
try {
res.render('alphabetPage.ejs')
}catch (err) {
console.error(err);}
}
},
};
}
14 changes: 5 additions & 9 deletions controllers/contact.controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const { isAdmin } = require("../middleware/auth");

module.exports = {
//Contact Page: app.get('/contact')
contact: async (req, res) => {
res.render("contactPage.ejs", {
admin: isAdmin(req?.user?.email),
});
},
};
//Contact Page: app.get('/contact')
contact: async (req,res) =>{
res.render('contactPage.ejs')
}
}
27 changes: 5 additions & 22 deletions controllers/entry.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const cloudinary = require("../middleware/cloudinary");
const Entry = require("../models/Entry");
const EntryModel = require("../models/entry-model");
const { isAdmin } = require("../middleware/auth");
// const fileUpload = require('express-fileupload');
// const { ObjectId } = require("mongodb");

Expand All @@ -15,18 +14,14 @@ module.exports = {
res.render("searchResults.ejs", {
searchQuery: name,
searchQueryResults: results,
admin: isAdmin(req?.user?.email),
});
},
//Get specific entry/word: app.get(/word/:id)
getID: async (req, res) => {
let name = req.params.id;
try {
await Entry.findOne({ _id: name }).then((data) => {
res.render("wordPage.ejs", {
searchQueryResults: data,
admin: isAdmin(req?.user?.email),
});
res.render("wordPage.ejs", { searchQueryResults: data });
});
} catch (error) {
console.error(error);
Expand All @@ -43,10 +38,7 @@ module.exports = {
// console.log(downloadURL)
try {
const data = await Entry.findOne({ _id: name });
res.render("editWord.ejs", {
result: data,
admin: isAdmin(req?.user?.email),
});
res.render("editWord.ejs", { result: data });
} catch (error) {
console.error(error);
}
Expand Down Expand Up @@ -137,10 +129,7 @@ module.exports = {

//Input Page app.get('/input')
getInputPage: async (req, res) => {
res.render("inputPage.ejs", {
errorMessage: "",
admin: isAdmin(req?.user?.email),
});
res.render("inputPage.ejs", { errorMessage: "" });
},

//Post entry app.post("/addEntry")
Expand All @@ -152,7 +141,6 @@ module.exports = {
if (!["audio/wav", "audio/mpeg"].includes(file.mimetype)) {
res.render("inputPage.ejs", {
errorMessage: "The type of audio file provided is not allowed.",
admin: isAdmin(req?.user?.email),
});
return;
}
Expand All @@ -177,20 +165,15 @@ module.exports = {

//Entry added to db: app.get('/entryAdded')
entryAdded: async (req, res) => {
res.render("completedEntry.ejs", {
admin: isAdmin(req?.user?.email),
});
res.render("completedEntry.ejs");
},

getID: async (req, res) => {
let name = req.params.id;
const entry = {};
try {
await Entry.findOne({ _id: name }).then((data) => {
res.render("wordPage.ejs", {
searchQueryResults: data,
admin: isAdmin(req?.user?.email),
});
res.render("wordPage.ejs", { searchQueryResults: data });
});
} catch (error) {
console.error(error);
Expand Down
4 changes: 1 addition & 3 deletions controllers/glossary.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { isAdmin } = require("../middleware/auth");
const EntryModel = require("../models/entry-model");
const { compareFunctions } = require("../utils/compareFunctions");

Expand All @@ -9,8 +8,7 @@ module.exports = {

res.render("glossary.ejs", {
entry: name,
entryList: results.sort(compareFunctions),
admin: isAdmin(req?.user?.email),
entryList: results.sort(compareFunctions)
});
},
};
7 changes: 1 addition & 6 deletions controllers/home.controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const { isAdmin } = require("../middleware/auth");

module.exports = {
getHomePage: (req, res) => {
res.render("homePage.ejs", {
user: req.user,
admin: isAdmin(req?.user?.email),
});
res.render("homePage.ejs", { user: req.user });
},
};
12 changes: 3 additions & 9 deletions middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
const adminList = [
"ruthreed.dev@gmail.com",
"speakpaiute@gmail.com",
];

module.exports = {
ensureAuth: function (req, res, next) {
//req.session.passport.user !== undefined
Expand All @@ -20,14 +15,13 @@ module.exports = {
}
},
ensureWhitelist: function (req, res, next) {
if (adminList.includes(req.user.email)) {
console.log(req.user);
if (emailWhitelist.includes(req.user.email)) {
return next();
} else {
// TODO: Make an error page saying that you don't have permissions to access this page.
res.redirect("/");
}
},
isAdmin: function (email) {
return email ? !!adminList.includes(email) : false;
},
};
const emailWhitelist = ["ruthreed.dev@gmail.com", "speakpaiute@gmail.com"];
4 changes: 1 addition & 3 deletions views/partials/navbar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<li><a href="/alphabet">Alphabet</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/glossary">Glossary</a></li>
<% if(user && admin){ %>
<li><a href="/input">Input</a></li>
<% } %> <% if(user){ %>
<% if(user){ %>
<li><a href="/auth/logout">Log out</a></li>
<li><a href=""><%=user.firstName%></a></li>
<% }else{ %>
Expand Down

0 comments on commit fdf7747

Please sign in to comment.