diff --git a/controllers/User.controller.js b/controllers/User.controller.js new file mode 100644 index 00000000..a02f1c4e --- /dev/null +++ b/controllers/User.controller.js @@ -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 }); + } +}; diff --git a/controllers/productController.js b/controllers/productController.js new file mode 100644 index 00000000..e69de29b diff --git a/middleware/authMiddleware.js b/middleware/authMiddleware.js new file mode 100644 index 00000000..d97dc394 --- /dev/null +++ b/middleware/authMiddleware.js @@ -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(); + }); +}; diff --git a/models/User.model.js b/models/User.model.js new file mode 100644 index 00000000..7f7df6eb --- /dev/null +++ b/models/User.model.js @@ -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; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bdf072c3..26e68466 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3361,7 +3361,7 @@ "version": "15.7.12", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.12.tgz", "integrity": "sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==", - "dev": true + "devOptional": true }, "node_modules/@types/raf": { "version": "3.4.3", @@ -3374,7 +3374,7 @@ "version": "18.3.3", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.3.tgz", "integrity": "sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==", - "dev": true, + "devOptional": true, "dependencies": { "@types/prop-types": "*", "csstype": "^3.0.2" diff --git a/public/Logo.svg b/public/Logo.svg new file mode 100644 index 00000000..aa18d055 --- /dev/null +++ b/public/Logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/sitemap.xml b/public/sitemap.xml new file mode 100644 index 00000000..e7bc88e1 --- /dev/null +++ b/public/sitemap.xml @@ -0,0 +1 @@ +https://www.vigybag.com/daily1.0https://www.vigybag.com/aboutweekly0.8https://www.vigybag.com/products/daily0.9https://www.vigybag.com/categories/daily0.9https://www.vigybag.com/blog/daily0.9https://www.vigybag.com/help/daily0.9https://www.vigybag.com/login/daily0.9https://www.vigybag.com/signup/daily0.9 \ No newline at end of file diff --git a/routes/authRoutes.js b/routes/authRoutes.js new file mode 100644 index 00000000..ec034c61 --- /dev/null +++ b/routes/authRoutes.js @@ -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; diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 00000000..0760efd1 --- /dev/null +++ b/routes/index.js @@ -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; diff --git a/routes/productRoutes.js b/routes/productRoutes.js new file mode 100644 index 00000000..50b8d806 --- /dev/null +++ b/routes/productRoutes.js @@ -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; diff --git a/src/components/Navbar/ProductsDropdown.jsx b/src/components/Navbar/ProductsDropdown.jsx index 6c19aaa3..df7a9876 100644 --- a/src/components/Navbar/ProductsDropdown.jsx +++ b/src/components/Navbar/ProductsDropdown.jsx @@ -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 ( -
- -
-
- - Fashion - - - Gifts - - - Furniture - - - Stationary - - - Body-Care - -
+const ProductsDropdown = ({ isOpen, onMouseEnter, onMouseLeave }) => ( +
+ +
+
+ + Fashion + + + Gifts + + + Furniture + + + Stationary + + + Body-Care +
- ); -}; +
+); export default ProductsDropdown; diff --git a/src/components/Navbar/UserNavbar .jsx b/src/components/Navbar/UserNavbar .jsx index 67e9adb9..824aa202 100644 --- a/src/components/Navbar/UserNavbar .jsx +++ b/src/components/Navbar/UserNavbar .jsx @@ -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?"); @@ -36,35 +39,6 @@ const Navbar = ({ isAdmin }) => {
- - - } - > - Home - - - - } - > - About Us - -
{ Body-Care
-
@@ -110,15 +83,13 @@ const Navbar = ({ isAdmin }) => { {isAdmin ? ( + 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"> )} @@ -134,15 +105,13 @@ const Navbar = ({ isAdmin }) => {
-
- - -
- - -
-

Or log in with:

-
- - -
+ {/* {showPassword ? ( + + ) : ( + + )} */} +
+
+ +
+ + -

- Don't have an account?{" "} - - Sign up - -

-
+ {/* Show admin access message if isAdmin is true */} + {isAdmin && ( +

Admin access granted!

+ )} -
- Illustration + {/* Social login buttons */} +
+

Or Login with:

+
+ + +
+ +

+ Create an account?{" "} + + Sign-Up + +

+
+ + {/* Illustration section */} +
+ Illustration
- - + ); }; + export default LoginForm; diff --git a/src/pages/Signup/Signup.jsx b/src/pages/Signup/Signup.jsx index bbb3f7aa..b4b51fa2 100644 --- a/src/pages/Signup/Signup.jsx +++ b/src/pages/Signup/Signup.jsx @@ -12,14 +12,19 @@ import axios from "axios"; import SignUp from "../../components/Buttons/SignUp"; import { FaEye, FaEyeSlash } from "react-icons/fa6"; import { ClipLoader, DotLoader } from "react-spinners"; -import toast, { Toaster } from "react-hot-toast"; -const containerClasses = "flex items-center bg-[#fff0e3ff] p-2 text-black rounded-xl"; -const inputClasses = "bg-[#fff0e3ff] flex-1 ml-2 text-black focus:outline-none rounded-xl"; -const formContainerClasses = "min-h-screen flex flex-col items-center justify-center bg-[#fff0e3ff] p-4"; -const cardClasses = "w-full max-w-4xl bg-[#fff0e3ff] dark:bg-zinc-800 rounded-lg shadow-lg overflow-hidden flex flex-col md:flex-row"; -const formSectionClasses = "relative rounded-lg w-full md:w-1/2 bg-zinc-800 text-zinc-200 p-6 flex flex-col justify-center"; -const illustrationSectionClasses = "rounded-lg hidden md:flex w-full md:w-1/2 p-8 items-center justify-center bg-[#c1cfabff] overflow-hidden"; +const containerClasses = + "flex items-center bg-[#fff0e3ff] p-2 text-black rounded-xl"; +const inputClasses = + "bg-[#fff0e3ff] flex-1 ml-2 text-black focus:outline-none rounded-xl"; +const formContainerClasses = + "min-h-screen flex flex-col items-center justify-center bg-[#fff0e3ff] p-4"; +const cardClasses = + "w-full max-w-4xl bg-[#fff0e3ff] dark:bg-zinc-800 rounded-lg shadow-lg overflow-hidden flex flex-col md:flex-row"; +const formSectionClasses = + "relative rounded-lg w-full md:w-1/2 bg-zinc-800 text-zinc-200 p-6 flex flex-col justify-center"; +const illustrationSectionClasses = + "rounded-lg hidden md:flex w-full md:w-1/2 p-8 items-center justify-center bg-[#c1cfabff] overflow-hidden"; const FormInput = ({ icon, placeholder, type = "text", value, onChange }) => { return ( @@ -52,7 +57,7 @@ const SignUpForm = () => { e.preventDefault(); setLoading(true); if (password !== confirmPassword) { - toast.error("Passwords do not match"); + alert("Passwords do not match"); console.log("Passwords do not match"); setLoading(false); return; @@ -69,7 +74,7 @@ const SignUpForm = () => { } ); - toast.success(response.data.message); + alert(response.data.message); navigate("/login"); setUsername(""); setEmail(""); @@ -77,8 +82,12 @@ const SignUpForm = () => { setPassword(""); setConfirmPassword(""); } catch (error) { - if (error.response && error.response.data && error.response.data.message) { - toast.error(error.response.data.message); + if ( + error.response && + error.response.data && + error.response.data.message + ) { + alert(error.response.data.message); console.log(error.response.data.message); } } finally { @@ -100,16 +109,22 @@ const SignUpForm = () => { setShowConfirmPassword(true); } } - return ( <>
- Logo + Logo
-

Sign Up

+

+ Sign Up +

{ value={password} onChange={(e) => setPassword(e.target.value)} /> + {/* {showPassword ? ( + + ) : ( + + )} */}
{ value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} /> + {/* {showConfirmPassword ? ( + + ) : ( + + )} */}
- +
- @@ -167,27 +209,39 @@ const SignUpForm = () => {

Or sign up with:

- Already have an account? Log in + Already have an account?{" "} + + Log in +

- Illustration + Illustration
- ); };