From b518628210f6bb9f7dec76989e90fc1e5e1d70e8 Mon Sep 17 00:00:00 2001 From: Suvadip-sana Date: Sat, 9 Nov 2024 14:59:14 +0530 Subject: [PATCH 1/5] Fix the dark mode map pop up --- views/show.ejs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/views/show.ejs b/views/show.ejs index 9165266c..983c1740 100644 --- a/views/show.ejs +++ b/views/show.ejs @@ -221,6 +221,9 @@ background-color: #323232; color: #fff !important; } + .mapboxgl-popup-content p{ + color: #555555 !important; + } } From 7a4c8a44708b56a1b029050d3f2eaaddfb259c82 Mon Sep 17 00:00:00 2001 From: Suvadip Sana Date: Sat, 9 Nov 2024 15:03:24 +0530 Subject: [PATCH 2/5] Delete app.js --- app.js | 250 --------------------------------------------------------- 1 file changed, 250 deletions(-) delete mode 100644 app.js diff --git a/app.js b/app.js deleted file mode 100644 index 55e714b2..00000000 --- a/app.js +++ /dev/null @@ -1,250 +0,0 @@ -if (process.env.NODE_ENV != "production") { - require('dotenv').config(); -} - -const port = 8080; -const express = require("express"); -const app = express(); -const mongoose = require("mongoose"); -const listing = require("./models/listing.js"); -const path = require("path"); -const methodOverride = require("method-override"); -const ejsMate = require("ejs-mate"); -const asyncwrap = require("./utils/error.js"); -const multer = require('multer'); -const { storage } = require("./cloudConfig.js"); -const upload = multer({ storage }); -const cookieparser = require("cookie-parser"); -const session = require("express-session"); -const MongoStore = require('connect-mongo'); -const flash = require("connect-flash"); -const passport=require("passport"); -const localStrategy=require("passport-local"); -const User=require("./models/user.js"); -const { isLoggedIn, isAdmin } = require("./middlewares/middleware.js"); -const {saveRedirectUrl}=require("./middlewares/middleware.js"); -const {isOwner,isAuthor}=require("./middlewares/middleware.js"); -const {index, newpost, createpost, editpost, saveEditpost,search, deletepost, showPost, bookinfFt, signup, likeListing }=require("./controllers/listing.js"); -const { dashboard, showuser, deleteUser, deleteListing, viewIndividualListing, viewListingReview, adminListEditRender, adminSaveEditList, showFeedbacks, deleteFeedback } = require("./controllers/admin.js") -const { signupRender, siggnedUp, logout, forgotPassword, passwordResetLink, resetPasswordTokenGet, resetPasswordTokenPatch, updatePasswordGet, updatePasswordPost } = require("./controllers/user.js") -const { viewProfile, profileGet, profilePost } = require("./controllers/profile.js"); -const { contactPage, aboutPage, termsPage, privacyPage, contributors } = require("./controllers/others.js") -const { deleteReview, reviewPost } = require("./controllers/reviews.js"); -const feedbackController = require('./controllers/feedback'); - -// const { feedbackPost } = require("./controllers/feedback.js"); - -const cors = require('cors'); -const { contactUsController } = require("./controllers/contactUs.js"); - -app.use(cors({ - origin: 'http://your-frontend-domain.com', - methods: ['GET', 'POST', 'PUT', 'DELETE'], - credentials: true -})); - -app.use(cookieparser()); - -const dbUrl = process.env.ATLAS_DB_TOKEN; - -async function main() { - await mongoose.connect(dbUrl); - console.log("database connected"); -} - -main().catch(err => console.log(err)); - -app.set("views", path.join(__dirname, "views")); -app.set("view engine", "ejs"); -app.use(express.static(path.join(__dirname, "/public"))); -app.use(methodOverride('_method')); -app.use(express.urlencoded({ extended: true })); -app.engine('ejs', ejsMate); -// app.use('/uploads', express.static(path.join(__dirname, '/uploads'))); -app.use(express.json()); - - -const store = MongoStore.create({ - mongoUrl: dbUrl, - crypto: { - secret: process.env.SECRET - }, - touchAfter: 24 * 3600, -}); - -store.on("error", (err) => { - console.log("error in mongo session store", err); -}); - -const sessionOptions = { - store, - secret: process.env.SECRET, - resave: false, - saveUninitialized: true, - cookie: { - expires: Date.now() + 7 * 24 * 60 * 60 * 1000, - maxAge: 7 * 24 * 60 * 60 * 1000, - httpOnly: true, - }, -}; - -app.use(session(sessionOptions)); -app.use(flash()); - -app.use(passport.initialize()); -app.use(passport.session()); -passport.use(new localStrategy(User.authenticate())); -passport.serializeUser(User.serializeUser()); -passport.deserializeUser(User.deserializeUser()); - -app.use((req, res, next) => { - res.locals.success = req.flash('success'); - res.locals.error = req.flash('error'); - res.locals.currUser = req.user || null; - - // Check if profile picture exists; if not, use a default URL - if (req.user && req.user.profilePicture && req.user.profilePicture.purl) { - let originalUrl = req.user.profilePicture.purl; - let modifiedProfilePic = originalUrl.replace("/upload", "/upload/q_auto,e_blur:50,w_250,h_250"); - res.locals.profilePic = modifiedProfilePic; - } - next(); -}); - - - -// ADMIN -// ADMIN - -app.get('/admin/dashboard',isLoggedIn ,isAdmin, asyncwrap(dashboard)); - -app.get('/admin/users',isLoggedIn ,isAdmin, asyncwrap(showuser)); - - -//ADMIN -app.delete('/admin/user/:id',isLoggedIn, isAdmin, asyncwrap(deleteUser)); - -app.delete('/admin/listing/:id',isLoggedIn, isAdmin, asyncwrap(deleteListing)); - - -app.get('/admin/listing/:id',isLoggedIn, isAdmin,asyncwrap(viewIndividualListing)); - -app.get('/admin/reviews/:id',isLoggedIn, isAdmin,asyncwrap(viewListingReview)); - -app.get('/admin/listing/edit/:id',isLoggedIn, isAdmin, asyncwrap(adminListEditRender)); - -app.put('/admin/listing/edit/:id',isLoggedIn, isAdmin, upload.array('listing[image]',10), asyncwrap(adminSaveEditList)); - -app.get('/admin/feedbacks', isLoggedIn, isAdmin, asyncwrap(showFeedbacks)); - -app.delete('/admin/feedbacks/:id',isLoggedIn, isAdmin, asyncwrap(deleteFeedback)); - -// ADMIN -// ADMIN - - -// Default route for '/' path -app.get("/", asyncwrap(async (req,res) => { - - const listings = await listing.find(); - res.render("index.ejs", { listings }); - -})); - -// Others page -app.get("/contact", contactPage); -app.post("/contact", asyncwrap(contactUsController)); -app.get('/about',asyncwrap (aboutPage)); -app.get('/terms', asyncwrap(termsPage)); -app.get('/privacy', asyncwrap(privacyPage)); -app.get('/contributors', asyncwrap(contributors)); - - // Login Route: Ensure return after authentication - app.route("/login") - .get( asyncwrap ((req,res) =>{ - res.render("login.ejs"); - })) - .post( - saveRedirectUrl, - passport.authenticate("local", { - failureRedirect: "/login", - failureFlash: true - }), (req, res) => { - req.flash("success", "Welcome back to wanderlust!"); - //admin login - if(req.user.isAdmin) { - req.flash("success","Welcome back to wanderlust! You are an admin."); - res.redirect("/admin/dashboard"); - } - let redirect=res.locals.redirectUrl||"/listing"; - res.redirect(redirect); // Redirect to a route that will display the message - }); - - -app.get("/signup", asyncwrap(signupRender)) - -app.post('/signup', asyncwrap(siggnedUp)) - -app.get("/logout", (logout)); - -app.get('/forgot-password', forgotPassword); - -app.post('/resetlink-password', passwordResetLink); - - -app.get('/resetPassword/:token', resetPasswordTokenGet); - -app.patch("/resetPassword/:token", resetPasswordTokenPatch); - -app.get('/user/updatePass', isLoggedIn, updatePasswordGet); - -app.post('/user/updatePass', isLoggedIn, updatePasswordPost); - - -// Profile -app.get('/profile', isLoggedIn, asyncwrap(viewProfile)); -app.get("/profile/edit", isLoggedIn, profileGet); -app.post('/profile/edit', isLoggedIn, upload.single("profileimage"), profilePost); - -// Listing controller -const listingController = require('./controllers/listing.js'); -// Create new listing form route -app.get("/listing/new", isLoggedIn, asyncwrap(listingController.newpost)); -// Listing routes -app.get("/listing", asyncwrap(index)); -app.post("/listing", upload.array('listing[image]', 10), isLoggedIn, asyncwrap(createpost)); -app.post("/listing/search", asyncwrap(search)); -app.get("/listing/:id/edit", isLoggedIn, isOwner, asyncwrap(editpost)); -app.put('/listing/:id', isLoggedIn, isOwner, upload.array('listing[image]', 10), asyncwrap(saveEditpost)); -app.delete("/listing/:id", isLoggedIn, isOwner, asyncwrap(deletepost)); -app.get("/listing/:id", asyncwrap(showPost)); -app.post('/listing/:id/like', isLoggedIn, asyncwrap(listingController.likeListing)); -// Booking page -app.get('/listing/:id/booking', bookinfFt); -// Feedback -app.post("/feedback", isLoggedIn, asyncwrap(feedbackController.feedbackPost)); - - -// Reviews -app.post("/listing/:id/review", isLoggedIn, asyncwrap(reviewPost)); -app.delete("/listing/:id/review/:reviewId", isLoggedIn, isAuthor, asyncwrap(deleteReview)); - -// Catch-all for invalid routes -app.use("*", (req, res) => { - res.render("not_found.ejs"); -}); - -// Error handling middleware -app.use((err, req, res, next) => { - const { status = 500, msg = "Something went wrong" } = err; - console.log("The error is --> ", err); - if (res.headersSent) { - return next(err); // Exit if headers already sent - } - res.status(status); - res.render("error.ejs", { msg, status }); -}); - -app.listen(port, () =>{ - console.log("server is listening on port", port); -}); From 0018d4146d3785f186df23b2367dfe4b481eb8b8 Mon Sep 17 00:00:00 2001 From: Suvadip Sana Date: Sat, 9 Nov 2024 15:03:52 +0530 Subject: [PATCH 3/5] Delete controllers/admin.js --- controllers/admin.js | 191 ------------------------------------------- 1 file changed, 191 deletions(-) delete mode 100644 controllers/admin.js diff --git a/controllers/admin.js b/controllers/admin.js deleted file mode 100644 index a8042085..00000000 --- a/controllers/admin.js +++ /dev/null @@ -1,191 +0,0 @@ -const listing = require("../models/listing.js"); -const User=require("../models/user.js"); -const Feedback=require("../models/feedback.js"); - - - -module.exports.dashboard = async (req, res) => { - try { - const listings = await listing.find().populate('owner');; - // console.log(listings.owner); - res.render('adminDashboard', { listings }); - } catch (error) { - console.error('Error fetching listings:', error); - res.status(500).send('Internal Server Error'); - } - }; - - - //manage users -module.exports.showuser = async (req, res) => { - try { - const users = await User.find(); - // console.log(users); - res.render('manageUser', { users }); - } catch (error) { - console.error('Error fetching Users:', error); - res.status(500).send('Internal Server Error'); - } - }; - - //route to delete users -module.exports.deleteUser = async (req, res) => { - try { - // console.log("Deleting user with ID:", req.params.id); - await User.findByIdAndDelete(req.params.id); - req.flash('success', 'User deleted!'); - res.redirect('/admin/users'); - } catch (error) { - res.status(500).send('Error deleting user: ' + error.message); - } - }; - - // Route to DELETE listings -module.exports.deleteListing = async (req, res) => { - try { - // console.log("Deleting listing with ID:", req.params.id); - await listing.findByIdAndDelete(req.params.id); - req.flash('success', 'Listing deleted!'); - res.redirect('/admin/dashboard'); - } catch (error) { - res.status(500).send('Error deleting listing: ' + error.message); - } - }; - - - // View manage listing from admin dashboard -module.exports.viewIndividualListing = async (req, res) => { - try { - const {id}=req.params; - // console.log(id); - const list = await listing.findById(id); - // console.log(list); - if (!list) { - return res.status(404).send('Listing not found'); - } - res.render('view_manage_listing.ejs', { list }); // Create a new view file called show.ejs or similar - } catch (err) { - res.status(500).send(err.message); - } - }; - - // View listing's reviews from admin dashboard -module.exports.viewListingReview = async (req, res) => { - try { - const {id}=req.params; - // console.log(id); - const list = await listing.findById(id).populate({ - path: 'reviews', - populate: { - path: 'author' - } - }) - .populate('owner'); - - // console.log(list.reviews[0].author.username); - - if (!list) { - return res.status(404).send('Listing not found'); - } - res.render('view_reviews.ejs', { list }); // Create a new view file called show.ejs or similar - } catch (err) { - res.status(500).send(err.message); - } - }; - - - // Render show edit form -module.exports.adminListEditRender = async (req, res) => { - const tags = ["Trending", "Surfing", "Amazing cities", "Beach", "Farms", "Lake", "Castles", "Rooms", "Forest", "Pool"]; - try { - // console.log(req.params.id); - const list = await listing.findById(req.params.id); - // console.log(list); - if (!list){ - return res.status(404).send("Listing not found"); - } - res.render('edit_list_admin', { list , tags}); - } catch (err) { - console.error(err); - res.status(500).send("Server error"); - } - }; - - - //update listing admin - module.exports.adminSaveEditList = async (req, res) => { - const { id } = req.params; - const { title, description, price, location, country, tags } = req.body.listing; - - try { - if (!req.body.listing) { - req.flash('error', ERROR_SEND_VALID_DATA); - return res.redirect(`/admin/listing/edit/${id}`); - } - - // Find the listing by ID - const up_listing = await listing.findById(id); - - // Update the fields - up_listing.title = title; - up_listing.description = description; - up_listing.price = price; - up_listing.location = location; - up_listing.country = country; - - // Update tags - set to empty array if no tags are selected - let tagArray = []; - if (tags) { - if (Array.isArray(tags)) { - tagArray = tags.map(tag => tag.trim()); - } else if (typeof tags === 'string') { - tagArray = tags.split(',').map(tag => tag.trim()); - } - } - up_listing.tags = tagArray; - - // Check if new images are uploaded - if (req.files && req.files.length > 0) { - // If new images are provided, replace the old ones (you may adjust this to add instead of replace) - up_listing.image = req.files.map(file => ({ - url: file.path, - filename: file.filename - })); - } - // Save the updated listing - await up_listing.save(); - - // Redirect to the admin dashboard or listing page after the update - res.redirect(`/admin/dashboard`); - } catch (error) { - console.error("Error updating listing:", error); - res.status(500).send("Error updating listing."); - } - }; - - // Route for show all the feedback - module.exports.showFeedbacks = async (req, res) => { - try { - const feedbacks = await Feedback.find(); - // console.log(users); - res.render('manageFeedback', { feedbacks }); - } catch (error) { - console.error('Error fetching Users:', error); - res.status(500).send('Internal Server Error'); - } - }; - - -//route to delete feedback -module.exports.deleteFeedback = async (req, res) => { - try { - // console.log("Deleting user with ID:", req.params.id); - await Feedback.findByIdAndDelete(req.params.id); - req.flash('success', 'Feedback deleted successfully!'); - res.redirect('/admin/feedbacks'); - } catch (error) { - req.flash('error', 'ERROR in delete feedback operation! Try again latter.'); - res.redirect('/admin/feedbacks'); - res.status(500).send('Error deleting user: ' + error.message); - } -}; \ No newline at end of file From 413660ea60837636c5dc59f39c8797a19fa41c20 Mon Sep 17 00:00:00 2001 From: Suvadip Sana Date: Sat, 9 Nov 2024 15:04:47 +0530 Subject: [PATCH 4/5] Delete views/manageFeedback.ejs --- views/manageFeedback.ejs | 109 --------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 views/manageFeedback.ejs diff --git a/views/manageFeedback.ejs b/views/manageFeedback.ejs deleted file mode 100644 index c126d76b..00000000 --- a/views/manageFeedback.ejs +++ /dev/null @@ -1,109 +0,0 @@ - -<% layout("/layouts/admin_boilerplate") %> - - - - - -
-

Feedback Management Dashboard.

- - - - - - - - - - - - <% feedbacks.forEach(feedback => { %> - - - - - - - - - <% }) %> - -
NameRatingCommentSubmitted At
<%= feedback.name %><%= feedback.rating %> ★<%= feedback.comment %><%= feedback.submittedAt %> -
- -
- -
-
-
-
- From b53664a15cd1df0e3667449f0e040b1bbd9c6e54 Mon Sep 17 00:00:00 2001 From: Suvadip Sana Date: Sat, 9 Nov 2024 15:05:05 +0530 Subject: [PATCH 5/5] Delete views/includes/admin_navbar.ejs --- views/includes/admin_navbar.ejs | 156 -------------------------------- 1 file changed, 156 deletions(-) delete mode 100644 views/includes/admin_navbar.ejs diff --git a/views/includes/admin_navbar.ejs b/views/includes/admin_navbar.ejs deleted file mode 100644 index 2960733f..00000000 --- a/views/includes/admin_navbar.ejs +++ /dev/null @@ -1,156 +0,0 @@ - - \ No newline at end of file