Skip to content

Commit

Permalink
Revert "bugs fixed"
Browse files Browse the repository at this point in the history
  • Loading branch information
codervivek5 authored Jul 9, 2024
1 parent 5ccb81d commit 72729fe
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 226 deletions.
25 changes: 25 additions & 0 deletions controllers/User.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const User = require("../models/User");

exports.signup = async (req, res) => {
try {
const { username, password } = req.body;
const newUser = await User.create({ username, password });
res.status(201).json(newUser);
} catch (error) {
res.status(500).json({ error: error.message });
}
};

exports.login = async (req, res) => {
try {
const { username, password } = req.body;
const user = await User.findOne({ username });

if (!user || user.password !== password) {
return res.status(401).json({ message: "Invalid username or password" });
}
res.status(200).json({ message: "Login successful" });
} catch (error) {
res.status(500).json({ error: error.message });
}
};
Empty file.
18 changes: 18 additions & 0 deletions middleware/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const jwt = require("jsonwebtoken");
const config = require("../config");

exports.verifyToken = (req, res, next) => {
const token = req.headers["authorization"];

if (!token) {
return res.status(401).json({ message: "Access token not provided" });
}

jwt.verify(token, config.jwtSecret, (err, decoded) => {
if (err) {
return res.status(401).json({ message: "Invalid token" });
}
req.user = decoded;
next();
});
};
13 changes: 13 additions & 0 deletions models/User.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mongoose = require('mongoose');


const userSchema = new mongoose.Schema({
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
});

// mobile with otp, login with google , login with fb

const User = mongoose.model('User',userSchema);

module.exports = User;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://www.vigybag.com/</loc><changefreq>daily</changefreq><priority>1.0</priority></url><url><loc>https://www.vigybag.com/about</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://www.vigybag.com/products/</loc><changefreq>daily</changefreq><priority>0.9</priority></url><url><loc>https://www.vigybag.com/categories/</loc><changefreq>daily</changefreq><priority>0.9</priority></url><url><loc>https://www.vigybag.com/blog/</loc><changefreq>daily</changefreq><priority>0.9</priority></url><url><loc>https://www.vigybag.com/help/</loc><changefreq>daily</changefreq><priority>0.9</priority></url><url><loc>https://www.vigybag.com/login/</loc><changefreq>daily</changefreq><priority>0.9</priority></url><url><loc>https://www.vigybag.com/signup/</loc><changefreq>daily</changefreq><priority>0.9</priority></url></urlset>
8 changes: 8 additions & 0 deletions routes/authRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require("express");
const router = express.Router();
const authController = require("../controllers/authController");

router.post("/signup", authController.signup);
router.post("/login", authController.login);

module.exports = router;
10 changes: 10 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require("express");
const router = express.Router();

const authRoutes = require("./authRoutes");
const productRoutes = require("./productRoutes.js");

router.use("/auth", authRoutes);
router.use("/products", productRoutes);

module.exports = router;
9 changes: 9 additions & 0 deletions routes/productRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require("express");
const router = express.Router();
const productController = require("../controllers/productController.js");

router.get("/", productController.getAllProducts);
router.get("/:id", productController.getProductById);
router.post("/", productController.createProduct);

module.exports = router;
145 changes: 65 additions & 80 deletions src/components/Navbar/ProductsDropdown.jsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,72 @@
import React, { useState, useEffect, useRef } from "react";
// ProductsDropdown.jsx
import React from "react";
import { Link } from "react-router-dom";
import { FaChevronDown } from "react-icons/fa";

const ProductsDropdown = () => {
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef(null);

const toggleDropdown = () => setIsOpen(!isOpen);

const handleClickOutside = (event) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
setIsOpen(false);
}
};

useEffect(() => {
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, []);

return (
<div className="relative" ref={dropdownRef}>
<button
type="button"
onClick={toggleDropdown}
className="text-black hover:text-gray-600 px-3 py-2 rounded-md text-lg font-medium flex items-center focus:outline-none"
>
<lord-icon
style={{
width: "25px",
height: "25px",
paddingTop: "0px",
paddingLeft: "1px",
}}
src="https://cdn.lordicon.com/pgmktfgp.json"
trigger="hover"
colors="primary:#15803D,secondary:#15803D"
></lord-icon>{" "}
Products
<FaChevronDown className="ml-1" />
</button>
<div
className={`${
isOpen ? "block" : "hidden"
} absolute mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50`}
>
<div className="py-1">
<Link
to="/popularCategories/fashionAccessories"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Fashion
</Link>
<Link
to="/popularCategories/customizedGifts"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Gifts
</Link>
<Link
to="/popularCategories/furnitureDecor"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Furniture
</Link>
<Link
to="/popularCategories/printingStationery"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Stationary
</Link>
<Link
to="/popularCategories/bodyCare"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Body-Care
</Link>
</div>
const ProductsDropdown = ({ isOpen, onMouseEnter, onMouseLeave }) => (
<div
className="relative group"
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
<button
type="button"
className="text-black hover:text-gray-600 px-3 py-2 rounded-md text-lg font-medium flex items-center focus:outline-none"
>
<lord-icon
style={{
width: "25px",
height: "25px",
paddingTop: "0px",
paddingLeft: "1px",
}}
src="https://cdn.lordicon.com/pgmktfgp.json"
trigger="hover"
colors="primary:#15803D,secondary:#15803D"
></lord-icon>{" "}
Products
<FaChevronDown className="ml-1" />
</button>
<div
className={`${
isOpen ? "block" : "hidden"
} absolute mt-2 w-48 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5`}
style={{ zIndex: "20" }}
>
<div className="py-1">
<Link
to="/popularCategories/fashionAccessories"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Fashion
</Link>
<Link
to="/popularCategories/customizedGifts"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Gifts
</Link>
<Link
to="/popularCategories/furnitureDecor"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Furniture
</Link>
<Link
to="/popularCategories/printingStationery"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Stationary
</Link>
<Link
to="/popularCategories/bodyCare"
className="text-green-800 hover:text-green-500 block px-4 py-2 text-sm"
>
Body-Care
</Link>
</div>
</div>
);
};
</div>
);

export default ProductsDropdown;
54 changes: 11 additions & 43 deletions src/components/Navbar/UserNavbar .jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import { Link } from "react-router-dom";
const Navbar = ({ isAdmin }) => {
const [isOpen, setIsOpen] = useState(false);
const [searchTerm, setSearchTerm] = useState("");
const [openDropdown, setOpenDropdown] = useState(null);
const navigate = useNavigate();
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";

const toggleNavbar = () => setIsOpen(!isOpen);
const handleSearch = (e) => setSearchTerm(e.target.value);
const handleDropdown = (dropdown) => setOpenDropdown(dropdown);
const handleDropdownLeave = () => setOpenDropdown(null);

const handleLogout = () => {
const confirmed = window.confirm("Are you sure you want to logout?");
Expand All @@ -36,35 +39,6 @@ const Navbar = ({ isAdmin }) => {
<NavLogo />
<div className="hidden md:block lg:block">
<div className="ml-10 flex items-baseline space-x-4">

<NavLink
to="/"
icon={
<lord-icon
src="https://cdn.lordicon.com/wmwqvixz.json"
trigger="hover"
colors="primary:#15803D"
style={{ width: "25px", height: "25px" }}
></lord-icon>
}
>
Home
</NavLink>
<ProductsDropdown />
<NavLink
to="/about"
icon={
<lord-icon
src="https://cdn.lordicon.com/jnzhohhs.json"
trigger="hover"
colors="primary:#15803D"
style={{ width: "25px", height: "25px" }}
></lord-icon>
}
>
About Us
</NavLink>

<div className="py-1 flex justify-evenly items-center">
<Link
to="/popularCategories/fashionAccessories"
Expand Down Expand Up @@ -92,7 +66,6 @@ const Navbar = ({ isAdmin }) => {
Body-Care
</Link>
</div>

</div>
</div>
</div>
Expand All @@ -110,15 +83,13 @@ const Navbar = ({ isAdmin }) => {
{isAdmin ? (
<Link
to="/admin/dashboard"
className="ml-4 text-green-800 hover:text-gray-600 flex items-center"
>
className="ml-4 text-green-800 hover:text-gray-600 flex items-center">
<FaUserCircle className="mr-2 text-3xl" />
</Link>
) : (
<Link
to="/dashboard"
className="ml-4 text-green-800 hover:text-gray-600 flex items-center"
>
className="ml-4 text-green-800 hover:text-gray-600 flex items-center">
<FaUserCircle className="mr-2 text-3xl" />
</Link>
)}
Expand All @@ -134,15 +105,13 @@ const Navbar = ({ isAdmin }) => {
<div className="-mr-2 flex md:hidden">
<button
onClick={toggleNavbar}
className="inline-flex items-center justify-center p-2 rounded-md text-green-800 hover:text-gray-600 focus:outline-none"
>
className="inline-flex items-center justify-center p-2 rounded-md text-green-800 hover:text-gray-600 focus:outline-none">
{isOpen ? (
<svg
className="h-6 w-6"
stroke="#15803D"
fill="#15803D"
viewBox="0 0 24 24"
>
viewBox="0 0 24 24">
<path
strokeLinecap="round"
strokeLinejoin="round"
Expand All @@ -155,8 +124,7 @@ const Navbar = ({ isAdmin }) => {
className="h-6 w-6"
stroke="#15803D"
fill="#15803D"
viewBox="0 0 24 24"
>
viewBox="0 0 24 24">
<path
strokeLinecap="round"
strokeLinejoin="round"
Expand All @@ -175,11 +143,11 @@ const Navbar = ({ isAdmin }) => {
isOpen={isOpen}
searchTerm={searchTerm}
handleSearch={handleSearch}
handleDropdown={() => {}}
openDropdown={null}
handleDropdown={handleDropdown}
openDropdown={openDropdown}
isLoggedIn={isLoggedIn}
handleLogout={handleLogout}
handleDropdownLeave={() => {}}
handleDropdownLeave={handleDropdownLeave}
/>
</nav>
);
Expand Down
Loading

0 comments on commit 72729fe

Please sign in to comment.