-
Sign Up
+
>
- )
-}
+ );
+};
-export default Register
\ No newline at end of file
+export default Register;
diff --git a/client/src/pages/SellCreditsInfo/BidModel.js b/client/src/pages/SellCreditsInfo/BidModel.js
index 81ee6ff..62f919e 100644
--- a/client/src/pages/SellCreditsInfo/BidModel.js
+++ b/client/src/pages/SellCreditsInfo/BidModel.js
@@ -34,12 +34,12 @@ function BidModel({ showBidModal, setShowBidModal, sellCredit, reloadData }) {
if (response.ok) {
message.success("Bid added successfully");
- message.success("🪙5 Credits are rewarded! 🎊");
+ message.success("🪙5 points are rewarded! 🎊");
// send notification to seller
const notifyUser = {
title: "A new bid has been placed",
- message: `A new bid has been placed on your carbon credits 🪙${sellCredit?.data?.sellCredits} for 🫰🏻 ₹ ${formDataWithUser?.bidAmount}`,
+ message: `A new bid has been placed on your carbon credits ${sellCredit?.data?.sellCredits} for 🫰🏻 ₹ ${formDataWithUser?.bidAmount}`,
user: sellCredit?.data?.user?._id,
onClick: `/profile`,
read: false,
diff --git a/server/routes/bidsRoute.js b/server/routes/bidsRoute.js
index 3df0997..443c37e 100644
--- a/server/routes/bidsRoute.js
+++ b/server/routes/bidsRoute.js
@@ -2,9 +2,7 @@ const express = require("express");
const router = new express.Router();
const Bid = require("../models/bid");
const authenticate = require("../middleware/authenticate");
-const morgan = require("morgan");
-router.use(morgan("combined"));
// place a new bid
router.post("/place-new-bid", authenticate, async (req, res) => {
const user = req.rootUser; // Assuming you have a valid user object in req.rootUser
@@ -25,9 +23,6 @@ router.post("/place-new-bid", authenticate, async (req, res) => {
// get all bids
router.post("/get-all-bids-for-all-users", authenticate, async (req, res) => {
- const user = req.rootUser;
- user.rewardCredits += 5;
- await user.save();
try {
const { selectedSellCredit} = req.body;
console.log("sss", selectedSellCredit);
@@ -50,8 +45,6 @@ router.post("/get-all-bids-for-all-users", authenticate, async (req, res) => {
router.post("/get-particular-all-bids", authenticate, async (req, res) => {
const user = req.rootUser;
- user.rewardCredits += 5;
- await user.save();
try {
const { selectedSellCredit} = req.body;
console.log("sss", selectedSellCredit);
diff --git a/server/routes/creditsFormRoute.js b/server/routes/creditsFormRoute.js
index ba58a8f..25cb577 100644
--- a/server/routes/creditsFormRoute.js
+++ b/server/routes/creditsFormRoute.js
@@ -60,8 +60,6 @@ router.get("/get-credit-forms", async (req, res) => {
// edit form
router.put("/edit-credit-forms/:id", authenticate, async (req, res) => {
- const user = req.rootUser;
-
try {
const { id } = req.params;
if (!ObjectId.isValid(id)) {
@@ -89,9 +87,6 @@ router.put("/edit-credit-forms/:id", authenticate, async (req, res) => {
// delete the form
router.delete("/delete-credit-forms/:id", authenticate, async (req, res) => {
- const user = req.rootUser;
- user.rewardCredits += 5;
- await user.save();
try {
await CreditForm.findByIdAndDelete(req.params.id);
res.send({
diff --git a/server/routes/userRoute.js b/server/routes/userRoute.js
index f77b9b8..e58f748 100644
--- a/server/routes/userRoute.js
+++ b/server/routes/userRoute.js
@@ -3,144 +3,144 @@ const router = new express.Router();
const userdb = require("../models/user");
const bcrypt = require("bcryptjs");
const authenticate = require("../middleware/authenticate");
-const morgan = require("morgan");
-const analyzeAccessLogs = require("../middleware/analyzeAccessLogs");
-router.use(morgan("combined"));
// for user registration
-router.post("/register", async(req, res) =>{
- const {fname, email, password, cpassword} = req.body;
- if(!fname || !email || !password || !cpassword){
- res.status(422).json({error: "fill all the details"})
+router.post("/register", async (req, res) => {
+ const { fname, email, password, cpassword } = req.body;
+ if (!fname || !email || !password || !cpassword) {
+ res.status(422).json({ error: "fill all the details" });
+ }
+ try {
+ // check if user exists
+ const preuser = await userdb.findOne({ email: email });
+ if (preuser) {
+ res.status(422).json({ error: "This Email is Already Exist" });
+ } else if (password !== cpassword) {
+ res
+ .status(422)
+ .json({ error: "Password and Confirm Password not match" });
+ } else {
+ // creating new user
+ const finalUser = new userdb({
+ fname,
+ email,
+ password,
+ cpassword,
+ });
+
+ // 10 points as reward upon registering
+ finalUser.rewardCredits = 10;
+
+ const storeData = await finalUser.save();
+ //console.log(storeData);
+ res.status(201).json({ status: 201, storeData });
}
- try{
- // check if user exists
- const preuser = await userdb.findOne({email: email});
- if(preuser){
- res.status(422).json({error: 'This Email is Already Exist'});
- }else if(password !== cpassword){
- res.status(422).json({error: "Password and Confirm Password not match"});
- }else{
- // creating new user
- const finalUser = new userdb({
- fname, email, password, cpassword
- });
-
- // 10 credits as reward upon registering
- finalUser.rewardCredits = 10;
-
- const storeData = await finalUser.save();
- //console.log(storeData);
- res.status(201).json({status:201, storeData});
- }
- }catch(error){
- res.status(422).json(error);
- console.log("catch error", error);
- }
+ } catch (error) {
+ res.status(422).json(error);
+ console.log("catch error", error);
+ }
});
router.post("/login", async (req, res) => {
- const { email, password } = req.body;
+ const { email, password } = req.body;
- if (!email || !password) {
- return res.status(422).json({ error: "Fill in all the details" });
- }
+ if (!email || !password) {
+ return res.status(422).json({ error: "Fill in all the details" });
+ }
- try {
- const userValid = await userdb.findOne({ email });
+ try {
+ const userValid = await userdb.findOne({ email });
- if (!userValid) {
- throw new Error("Invalid details");
- }
+ if (!userValid) {
+ throw new Error("Invalid details");
+ }
- if (userValid.status === "blocked") {
- return res.status(422).json({ error: "User account is blocked" });
- }
+ if (userValid.status === "blocked") {
+ return res.status(422).json({ error: "User account is blocked" });
+ }
- const isMatch = await bcrypt.compare(password, userValid.password);
+ const isMatch = await bcrypt.compare(password, userValid.password);
- if (!isMatch) {
- return res.status(422).json({ error: "Invalid details" });
- }
-
- const token = await userValid.generateAuthtoken();
+ if (!isMatch) {
+ return res.status(422).json({ error: "Invalid details" });
+ }
- res.cookie("usercookie", token, {
- expires: new Date(Date.now() + 9000000),
- httpOnly: true
- });
+ const token = await userValid.generateAuthtoken();
- const result = {
- userValid,
- token
- };
+ res.cookie("usercookie", token, {
+ expires: new Date(Date.now() + 9000000),
+ httpOnly: true,
+ });
- return res.status(201).json({ status: 201, result });
- } catch (error) {
- console.error("Login error:", error);
- return res.status(500).json({ error: "Internal server error" });
- }
+ const result = {
+ userValid,
+ token,
+ };
+
+ return res.status(201).json({ status: 201, result });
+ } catch (error) {
+ console.error("Login error:", error);
+ return res.status(500).json({ error: "Internal server error" });
+ }
});
// user valid
-router.get("/validuser", authenticate, async(req,res)=>{
- try {
- const ValidUserOne = await userdb.findOne({_id:req.userId});
- res.status(201).json({status:201,ValidUserOne});
- } catch (error) {
- res.status(401).json({status:401,error});
- }
+router.get("/validuser", authenticate, async (req, res) => {
+ try {
+ const ValidUserOne = await userdb.findOne({ _id: req.userId });
+ res.status(201).json({ status: 201, ValidUserOne });
+ } catch (error) {
+ res.status(401).json({ status: 401, error });
+ }
});
// user logout
-router.get("/logout", authenticate, async(req,res) =>{
- try {
- req.rootUser.tokens = req.rootUser.tokens.filter((curelem)=>{
- return curelem.token !== req.token
- });
-
- res.clearCookie("usercookie",{path:"/"});
-
- res.status(201).json({status:201})
-
- } catch (error) {
- res.status(401).json({status:401,error})
- }
+router.get("/logout", authenticate, async (req, res) => {
+ try {
+ req.rootUser.tokens = req.rootUser.tokens.filter((curelem) => {
+ return curelem.token !== req.token;
+ });
+
+ res.clearCookie("usercookie", { path: "/" });
+
+ res.status(201).json({ status: 201 });
+ } catch (error) {
+ res.status(401).json({ status: 401, error });
+ }
});
// get all users
-router.get("/get-users", authenticate, async(req, res) => {
- try{
- const users = await userdb.find();
- res.send({
- success: true,
- message: "Users fetched successfully",
- data: users,
- });
- }catch(error){
- res.send({
- success: false,
- message: error.message,
- });
- }
+router.get("/get-users", authenticate, async (req, res) => {
+ try {
+ const users = await userdb.find();
+ res.send({
+ success: true,
+ message: "Users fetched successfully",
+ data: users,
+ });
+ } catch (error) {
+ res.send({
+ success: false,
+ message: error.message,
+ });
+ }
});
// update user status
-router.put("/update-user-status/:id", authenticate, async(req, res) => {
- try{
- const { status } = req.body;
- await userdb.findByIdAndUpdate(req.params.id, { status });
- res.send({
- success: true,
- message: "User status updated successfully",
- })
- }catch(error){
- res.send({
- success: false,
- message: error.message,
- });
- }
+router.put("/update-user-status/:id", authenticate, async (req, res) => {
+ try {
+ const { status } = req.body;
+ await userdb.findByIdAndUpdate(req.params.id, { status });
+ res.send({
+ success: true,
+ message: "User status updated successfully",
+ });
+ } catch (error) {
+ res.send({
+ success: false,
+ message: error.message,
+ });
+ }
});
module.exports = router;
-