diff --git a/package-lock.json b/package-lock.json index 15e7349..0914d2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "express-session": "^1.17.3", "mongoose": "^7.4.5", "multer": "^1.4.5-lts.1", - "path": "^0.12.7" + "path": "^0.12.7", + "zlib": "^1.0.5" }, "devDependencies": { "nodemon": "^3.0.1" @@ -3393,6 +3394,15 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/zlib": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/zlib/-/zlib-1.0.5.tgz", + "integrity": "sha512-40fpE2II+Cd3k8HWTWONfeKE2jL+P42iWJ1zzps5W51qcTsOUKM5Q5m2PFb0CLxlmFAaUuUdJGc3OfZy947v0w==", + "hasInstallScript": true, + "engines": { + "node": ">=0.2.0" + } } } } diff --git a/package.json b/package.json index 95a2b8b..6b1ec93 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "express-session": "^1.17.3", "mongoose": "^7.4.5", "multer": "^1.4.5-lts.1", - "path": "^0.12.7" + "path": "^0.12.7", + "zlib": "^1.0.5" }, "devDependencies": { "nodemon": "^3.0.1" diff --git a/routes/Admin/dashboard.js b/routes/Admin/dashboard.js index f1f184e..072462e 100644 --- a/routes/Admin/dashboard.js +++ b/routes/Admin/dashboard.js @@ -3,16 +3,52 @@ const { MongoClient } = require("mongodb"); const router = express.Router(); const bcrypt = require("bcrypt"); const { connect, getCollection } = require("../../db"); +const { ObjectId } = require("mongodb"); (async () => { try { // Get a reference to the users collection const userCollection = await getCollection("users"); - router.get("/dashboard", (req, res) => { + const productCollection = await getCollection("products"); + router.get("/dashboard/users", async (req, res) => { if (req.session.isAuthenticated && req.session.role == "admin") { const username = req.session.username; - // Access session data here, e.g., username - res.send(`

ADMIN DASHBOARD

`); + const users = await userCollection.find({}).toArray(); + const visitors = users.filter((user) => user.role === "visitor"); + res.render("adminVisitors", { visitors: visitors }); + //res.render("dashboard", { username }); + } else { + // Redirect or handle unauthenticated access + res.redirect("/login"); + } + }); + router.get("/dashboard/company", async (req, res) => { + if (req.session.isAuthenticated && req.session.role == "admin") { + const username = req.session.username; + const users = await userCollection.find({}).toArray(); + const visitors = users.filter((user) => user.role === "company"); + res.render("adminCompany", { visitors: visitors }); + //res.render("dashboard", { username }); + } else { + // Redirect or handle unauthenticated access + res.redirect("/login"); + } + }); + router.get("/dashboard/products", async (req, res) => { + if (req.session.isAuthenticated && req.session.role == "admin") { + const username = req.session.username; + const products = await productCollection.find({}).toArray(); + + for (let product of products) { + const user = await userCollection.findOne({ + _id: new ObjectId(product.createdBy), + }); + if (user) { + product.CreatedByUser = user.name; + } + } + console.log(products); + res.render("adminProducts", { products: products }); //res.render("dashboard", { username }); } else { // Redirect or handle unauthenticated access @@ -23,3 +59,8 @@ const { connect, getCollection } = require("../../db"); } })(); module.exports = router; +// diff --git a/routes/Company/company.js b/routes/Company/company.js new file mode 100644 index 0000000..003e6f9 --- /dev/null +++ b/routes/Company/company.js @@ -0,0 +1,50 @@ +const express = require("express"); +const { MongoClient } = require("mongodb"); +const router = express.Router(); +const bcrypt = require("bcrypt"); +const { connect, getCollection } = require("../../db"); +const { ObjectId } = require("mongodb"); + +(async () => { + try { + const userCollection = await getCollection("users"); + const productsCollection = await getCollection("products"); + router.get("/company/:id", async (req, res) => { + try { + const company = await userCollection.findOne({ + _id: new ObjectId(req.params.id), + }); + + const products = await productsCollection + .find({ + createdBy: req.params.id, + }) + .toArray(); + // console.log(products, company); + let loggedInUser = await userCollection.findOne({ + _id: new ObjectId(req.session.username), + }); + let cartItemCount = 0; + if (req.session.role == "visitor") { + cartItemCount = loggedInUser.cart.length; + } + + res.render("company", { + loggedIn: req.session.username ? true : false, + user: req.session, + products: products, + company: company, + logo: loggedInUser, + cartCount: cartItemCount, + }); + } catch (error) { + res.status(500).send({ message: "Server error" }); + } + }); + } finally { + // Ensures that the client will close when you finish/error + // await client.close(); + } +})(); + +module.exports = router; diff --git a/routes/Company/coverPicture.js b/routes/Company/coverPicture.js index d9af84c..fcec06b 100644 --- a/routes/Company/coverPicture.js +++ b/routes/Company/coverPicture.js @@ -1,10 +1,9 @@ const express = require("express"); -const { MongoClient } = require("mongodb"); const router = express.Router(); -const bcrypt = require("bcrypt"); -const { connect, getCollection } = require("../../db"); +const { getCollection } = require("../../db"); const { ObjectId } = require("mongodb"); const multer = require("multer"); +const fs = require("fs"); const storage = multer.diskStorage({ destination: function (req, file, cb) { @@ -32,17 +31,16 @@ const upload = multer({ storage: storage }); // Assuming 'cover' is the name of the form field in your client-side form const coverImage = req.file.path; // get the path of the uploaded file - // Update the user document with the cover image path const result = await userCollection.updateOne( { _id: new ObjectId(id) }, { $set: { cover: coverImage } } ); - - if (result.modifiedCount === 1) { - res.redirect(`/cover/${id}`); - } else { - res.status(500).send({ message: "Failed to upload cover image" }); - } + res.redirect(`/cover/${id}`); + // if (result.modifiedCount === 1) { + // + // } else { + // res.status(500).send({ message: "Failed to upload cover image" }); + // } }); router.get("/cover/:id", async (req, res) => { diff --git a/routes/Company/logo.js b/routes/Company/logo.js index 56c3071..8e3f070 100644 --- a/routes/Company/logo.js +++ b/routes/Company/logo.js @@ -1,10 +1,10 @@ const express = require("express"); -const { MongoClient } = require("mongodb"); const router = express.Router(); -const bcrypt = require("bcrypt"); -const { connect, getCollection } = require("../../db"); +const { getCollection } = require("../../db"); const { ObjectId } = require("mongodb"); const multer = require("multer"); +const fs = require("fs"); +const zlib = require("zlib"); const storage = multer.diskStorage({ destination: function (req, file, cb) { @@ -32,27 +32,25 @@ const upload = multer({ storage: storage }); // Assuming 'cover' is the name of the form field in your client-side form const logoImage = req.file.path; // get the path of the uploaded file - // Update the user document with the cover image path + // Convert image to base64 + // const logoImageBase64 = fs.readFileSync(logoImage, { + // encoding: "base64", + // }); + // const compressedImage = zlib + // .deflateSync(Buffer.from(logoImageBase64)) + // .toString("base64"); const result = await userCollection.updateOne( { _id: new ObjectId(id) }, { $set: { logo: logoImage } } ); - - if (result.modifiedCount === 1) { - res.redirect(`/logo/${id}`); - } else { - res.status(500).send({ message: "Failed to upload Logo image" }); - } + res.redirect(`/logo/${id}`); }); router.get("/logo/:id", async (req, res) => { - // Redirect to / - // Get the user id from the request parameters const id = req.params.id; let idString = id.toString(); const user = await userCollection.findOne({ _id: new ObjectId(id) }); user._id = idString; - // Render the 'cover' view and pass the user data and id to it res.render("company/logo", { user: user }); }); } finally { diff --git a/routes/Mutual/landing.js b/routes/Mutual/landing.js index 3c70123..9916f0c 100644 --- a/routes/Mutual/landing.js +++ b/routes/Mutual/landing.js @@ -5,6 +5,7 @@ const bcrypt = require("bcrypt"); const { connect, getCollection } = require("../../db"); const { ObjectId } = require("mongodb"); const multer = require("multer"); +const zlib = require("zlib"); const storage = multer.diskStorage({ destination: function (req, file, cb) { @@ -23,10 +24,15 @@ const upload = multer({ storage: storage }); const productsCollection = await getCollection("products"); router.get("/", async (req, res) => { const products = await productsCollection.find().toArray(); - const users = await userCollection.find({}, { cover: 1 }).toArray(); + const companyUsers = await userCollection.find({}).toArray(); + const companies = companyUsers.filter((user) => user.role === "company"); + const users = await userCollection + .find({}, { cover: 1, logo: 1 }) + .toArray(); const covers = users .filter((user) => user.cover) .map((user) => user.cover); + const logos = users.filter((user) => user.logo).map((user) => user.logo); let loggedInUser = await userCollection.findOne({ _id: new ObjectId(req.session.username), }); @@ -35,11 +41,11 @@ const upload = multer({ storage: storage }); cartItemCount = loggedInUser.cart.length; } - console.log(loggedInUser); res.render("landing", { loggedIn: req.session.username ? true : false, user: req.session, - products: products, + companies: companies, + logos: logos, covers: covers, logo: loggedInUser, cartCount: cartItemCount, diff --git a/routes/Visitor/addtocart.js b/routes/Visitor/addtocart.js index f9192de..d99d0cd 100644 --- a/routes/Visitor/addtocart.js +++ b/routes/Visitor/addtocart.js @@ -22,6 +22,8 @@ const { ObjectId } = require("mongodb"); const user = await userCollection.findOne({ _id: userId }); if (!user) { return res.status(404).send({ message: "User not found" }); + } else if (user.role != "visitor") { + return res.status(404).send({ message: "User is not a Visitor" }); } // Initialize cart if it does not exist diff --git a/server.js b/server.js index 1d96642..f55ef75 100644 --- a/server.js +++ b/server.js @@ -17,6 +17,7 @@ const coverRouter = require("./routes/Company/coverPicture"); const logoRouter = require("./routes/Company/logo"); const productRouter = require("./routes/Mutual/product"); const productsRouter = require("./routes/Company/products"); +const companyRouter = require("./routes/Company/company"); const createproductsRouter = require("./routes/Company/createproduct"); const editproductsRouter = require("./routes/Company/editproduct"); const deleteproductsRouter = require("./routes/Company/deleteproduct"); @@ -83,6 +84,7 @@ app.use(logoRouter); app.use(productsRouter); app.use(productRouter); +app.use(companyRouter); app.use(cartRouter); @@ -129,5 +131,5 @@ app.use(contactusRouter); app.use(logoutRouter); app.listen(7000, () => { - console.log("Server listening on port 7000"); + console.log("Server listening on port http://localhost:7000"); }); diff --git a/uploads/61p6R+WqedL._SX522_.jpg b/uploads/61p6R+WqedL._SX522_.jpg deleted file mode 100644 index 67ce446..0000000 Binary files a/uploads/61p6R+WqedL._SX522_.jpg and /dev/null differ diff --git a/uploads/61q-bIO7ecL._SX522_.jpg b/uploads/61q-bIO7ecL._SX522_.jpg deleted file mode 100644 index 6b3c939..0000000 Binary files a/uploads/61q-bIO7ecL._SX522_.jpg and /dev/null differ diff --git a/uploads/811aBK9bUFL._SX522_.jpg b/uploads/811aBK9bUFL._SX522_.jpg deleted file mode 100644 index 89cd9e4..0000000 Binary files a/uploads/811aBK9bUFL._SX522_.jpg and /dev/null differ diff --git a/uploads/Acxiom.png b/uploads/Acxiom.png deleted file mode 100644 index dd92941..0000000 Binary files a/uploads/Acxiom.png and /dev/null differ diff --git a/uploads/COVERPCSLIDE.png b/uploads/COVERPCSLIDE.png deleted file mode 100644 index 249761f..0000000 Binary files a/uploads/COVERPCSLIDE.png and /dev/null differ diff --git a/uploads/Cover_64f2c6ca44233e3c20d52f58.jpeg b/uploads/Cover_64f2c6ca44233e3c20d52f58.jpeg new file mode 100644 index 0000000..9fbc9f4 Binary files /dev/null and b/uploads/Cover_64f2c6ca44233e3c20d52f58.jpeg differ diff --git a/uploads/Cover_65112b86fe52d3973e892b51.jpeg b/uploads/Cover_65112b86fe52d3973e892b51.jpeg new file mode 100644 index 0000000..2620b03 Binary files /dev/null and b/uploads/Cover_65112b86fe52d3973e892b51.jpeg differ diff --git a/uploads/Logo_64f2c6ca44233e3c20d52f58.jpeg b/uploads/Logo_64f2c6ca44233e3c20d52f58.jpeg new file mode 100644 index 0000000..ed784ac Binary files /dev/null and b/uploads/Logo_64f2c6ca44233e3c20d52f58.jpeg differ diff --git a/uploads/Logo_65112b86fe52d3973e892b51.jpeg b/uploads/Logo_65112b86fe52d3973e892b51.jpeg new file mode 100644 index 0000000..208246b Binary files /dev/null and b/uploads/Logo_65112b86fe52d3973e892b51.jpeg differ diff --git a/uploads/Sign2.jpg b/uploads/Sign2.jpg deleted file mode 100644 index 17127e5..0000000 Binary files a/uploads/Sign2.jpg and /dev/null differ diff --git a/uploads/image 1.jpg b/uploads/image 1.jpg deleted file mode 100644 index 76b054e..0000000 Binary files a/uploads/image 1.jpg and /dev/null differ diff --git a/uploads/photo-1682687982470-8f1b0e79151a.jpeg b/uploads/photo-1682687982470-8f1b0e79151a.jpeg deleted file mode 100644 index 4c6ca76..0000000 Binary files a/uploads/photo-1682687982470-8f1b0e79151a.jpeg and /dev/null differ diff --git a/uploads/photo-1682695796954-bad0d0f59ff1.jpeg b/uploads/photo-1682695796954-bad0d0f59ff1.jpeg deleted file mode 100644 index aa5c222..0000000 Binary files a/uploads/photo-1682695796954-bad0d0f59ff1.jpeg and /dev/null differ diff --git a/uploads/photo-1683009427479-c7e36bbb7bca.jpeg b/uploads/photo-1683009427479-c7e36bbb7bca.jpeg deleted file mode 100644 index 3015b78..0000000 Binary files a/uploads/photo-1683009427479-c7e36bbb7bca.jpeg and /dev/null differ diff --git a/uploads/premium_photo-1680127401632-dcc0f571d4b9.jpeg b/uploads/premium_photo-1680127401632-dcc0f571d4b9.jpeg deleted file mode 100644 index b86bf37..0000000 Binary files a/uploads/premium_photo-1680127401632-dcc0f571d4b9.jpeg and /dev/null differ diff --git a/uploads/programming-css-html-code-wallpaper-c920a8cd218a4dcb26f728ff90a1366d.jpg b/uploads/programming-css-html-code-wallpaper-c920a8cd218a4dcb26f728ff90a1366d.jpg deleted file mode 100644 index bd116db..0000000 Binary files a/uploads/programming-css-html-code-wallpaper-c920a8cd218a4dcb26f728ff90a1366d.jpg and /dev/null differ diff --git a/uploads/quote-hello-world-computer-hd-wallpaper-e9e0288df18a2debe69758bf7051b64d.jpg b/uploads/quote-hello-world-computer-hd-wallpaper-e9e0288df18a2debe69758bf7051b64d.jpg deleted file mode 100644 index e307276..0000000 Binary files a/uploads/quote-hello-world-computer-hd-wallpaper-e9e0288df18a2debe69758bf7051b64d.jpg and /dev/null differ diff --git a/uploads/tree-736885_1280.jpg b/uploads/tree-736885_1280.jpg new file mode 100644 index 0000000..4c3aeaf Binary files /dev/null and b/uploads/tree-736885_1280.jpg differ diff --git a/uploads/urgentbacups.jpg b/uploads/urgentbacups.jpg deleted file mode 100644 index 1a01b89..0000000 Binary files a/uploads/urgentbacups.jpg and /dev/null differ diff --git a/uploads/vardagen-cooks-knife-dark-grey__0710384_pe727512_s5.jpg b/uploads/vardagen-cooks-knife-dark-grey__0710384_pe727512_s5.jpg deleted file mode 100644 index fb12ddd..0000000 Binary files a/uploads/vardagen-cooks-knife-dark-grey__0710384_pe727512_s5.jpg and /dev/null differ diff --git a/views/adminCompany.ejs b/views/adminCompany.ejs new file mode 100644 index 0000000..58ef8ac --- /dev/null +++ b/views/adminCompany.ejs @@ -0,0 +1,42 @@ + + + + + + + Dashboard + + + + + +

Dashboard

+

All Users +

+ + + + \ No newline at end of file diff --git a/views/adminProducts.ejs b/views/adminProducts.ejs new file mode 100644 index 0000000..fb53b4c --- /dev/null +++ b/views/adminProducts.ejs @@ -0,0 +1,47 @@ + + + + + + + Dashboard + + + + + +

Dashboard

+

All Users +

+ + + + \ No newline at end of file diff --git a/views/adminVisitors.ejs b/views/adminVisitors.ejs new file mode 100644 index 0000000..58ef8ac --- /dev/null +++ b/views/adminVisitors.ejs @@ -0,0 +1,42 @@ + + + + + + + Dashboard + + + + + +

Dashboard

+

All Users +

+ + + + \ No newline at end of file diff --git a/views/company.ejs b/views/company.ejs new file mode 100644 index 0000000..9275107 --- /dev/null +++ b/views/company.ejs @@ -0,0 +1,404 @@ + + + + + + + Document + + + + + + + +
+
+ + +

+ <%=company.companyName %> +

+

+ <%=company.bio %> + Bio +

+

+ <%=company.companyType%> + CompanyType +

+
+ + + +
+ +
+ <% if (!products || products.length===0) { %> +

You Have No Products

+ <% } else { %> + <% products.forEach(function(product) { %> + +
+
+
+ +
+
+

+ <%=product.name%> +

+

+ ₹<%=product.offer%> +

+

₹ + <%=product.price%> +

+
+ +
+
Owner +
+
+
+
+
+

+ <%=company.name %> +

+

+ <%=company.phone %> +

+
+
+
+
+
+ +
+ + <% }); %> + <% } %> + + +
+
+ + + \ No newline at end of file diff --git a/views/company/cover.ejs b/views/company/cover.ejs index 8949540..434890c 100644 --- a/views/company/cover.ejs +++ b/views/company/cover.ejs @@ -6,6 +6,7 @@ Your Title + @@ -115,7 +116,7 @@
- <% if (user.role=="visitor" ) { %> + <% if (user.role==="visitor" ) { %>
  • @@ -139,7 +140,7 @@ Open user menu
  • @@ -162,12 +163,17 @@ tabindex="-1" id="user-menu-item-2">Logo My Products - <% } else { %> + <% } else if(user.role=="visitor" ) { %> Profile My Cart - <% } %> + <% } else{%> + Admin Profile + All Users + <% } %> @@ -221,14 +227,14 @@
    <% if(covers.length> 0) { %> <% covers.forEach(function(cover, index) { %> - Cover image + Cover image'> + <% }); %> <% } else { %> Default image <% } %>
    - + +
    +
    + <% if(logos.length> 0) { %> + <% logos.forEach(function(logo, index) { %> +
    + +
    + <% }); %> + <% } else { %> + Default image + <% } %> +
    +
    -

    All Products

    - -
    +

    All companies

    +
    +
    + <% if (!companies || companies.length===0) { %> +

    You Have No companies

    + <% } else { %> + <% companies.forEach(function(company) { %> + + - - <% }); %> - <% } %>
    +
    diff --git a/views/product.ejs b/views/product.ejs index 4439633..6e4dd9d 100644 --- a/views/product.ejs +++ b/views/product.ejs @@ -1,200 +1,245 @@ - - - - - Product - - - - - - - - -
    -
    -
    -
    -
    -
    -
    -
    - - -
    - -
    - -
    - -
    - -
    -
    - -
    - -
    + + +
    + +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + +
    -
    -
    -

    <%= product.name %>

    -

    By

    <%= createdBy.name %>

    -
    -
    -
    - - <%= product.offer %> -
    -
    -
    -

    ₹<%= product.price %>

    - -

    Inclusive of all Taxes.

    - -
    - + +
    +
    -
    -
    -

    Slogan: <%= product.slogan %>

    -

    Website: <%= product.websitelink %>

    -

    Address: <%= product.address %>

    -

    Description: <%= product.discription %>

    + +
    + +
    +
    + +
    + +
    +
    +
    +
    +

    + <%= product.name %> +

    +

    By +

    + <%= createdBy.name %> +

    +

    +
    +
    +
    + + + <%= product.offer %> +
    +
    +

    ₹<%= + product.price %> +

    + +

    Inclusive of all Taxes.

    + +
    + +
    +
    +
    +

    Slogan: <%= product.slogan %> +

    +

    Website: <%= product.websitelink %> +

    +

    Address: <%= product.address %> +

    +

    Description: <%= product.discription %> +

    +
    + +
    + + +
    -
    - - \ No newline at end of file +
    +
    + + + \ No newline at end of file