From d3dd309ff4071d2146ac3c4735f9ef693ccae3bc Mon Sep 17 00:00:00 2001 From: garimasingh22 <44470092+garimasingh22@users.noreply.github.com> Date: Thu, 27 Aug 2020 13:27:19 +0530 Subject: [PATCH 1/2] edit page fornt end and backend --- app.js | 49 +++++++++++---------- routes/api/edit.js | 67 ++++++++++++++++++++++++++++ views/edit.ejs | 98 ++++++++++++++++++++++++++++++++++++++++- views/partials/_nav.ejs | 89 +++++++++++++++++++------------------ 4 files changed, 235 insertions(+), 68 deletions(-) diff --git a/app.js b/app.js index b2669f7..f795c00 100644 --- a/app.js +++ b/app.js @@ -41,19 +41,19 @@ app.use(express.json()); // Method override app.use( - methodOverride(function (req, res) { - if (req.body && typeof req.body === "object" && "_method" in req.body) { - // look in urlencoded POST bodies and delete it - let method = req.body._method; - delete req.body._method; - return method; - } - }) + methodOverride(function(req, res) { + if (req.body && typeof req.body === "object" && "_method" in req.body) { + // look in urlencoded POST bodies and delete it + let method = req.body._method; + delete req.body._method; + return method; + } + }) ); // Logging if (process.env.NODE_ENV === "development") { - app.use(morgan("dev")); + app.use(morgan("dev")); } // EJS @@ -66,12 +66,12 @@ app.use(expressLayouts); // Sessions app.use( - session({ - secret: "keyboard cat", - resave: false, - saveUninitialized: false, - store: new MongoStore({ mongooseConnection: mongoose.connection }), - }) + session({ + secret: "keyboard cat", + resave: false, + saveUninitialized: false, + store: new MongoStore({ mongooseConnection: mongoose.connection }), + }) ); // cookie middleware @@ -85,12 +85,12 @@ app.use(passport.session()); app.use(flash()); // Set Global variables -app.use(function (req, res, next) { - res.locals.user = req.user || null; - res.locals.success_msg = req.flash("success_msg"); - res.locals.error_msg = req.flash("error_msg"); - res.locals.error = req.flash("error"); - next(); +app.use(function(req, res, next) { + res.locals.user = req.user || null; + res.locals.success_msg = req.flash("success_msg"); + res.locals.error_msg = req.flash("error_msg"); + res.locals.error = req.flash("error"); + next(); }); // Static folder @@ -108,12 +108,13 @@ app.use("/done", require("./routes/api/done")); app.use("/addBalance", require("./routes/api/addBalance")); app.use("/transaction", require("./routes/api/transaction")); app.use("/search", require("./routes/api/search")); +app.use("/edit", require("./routes/api/edit")); // Port: Love You 3000 const PORT = process.env.PORT || 3000; // Server Listening app.listen( - PORT, - console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`) -); + PORT, + console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`) +); \ No newline at end of file diff --git a/routes/api/edit.js b/routes/api/edit.js index 685ea2f..eb4944e 100644 --- a/routes/api/edit.js +++ b/routes/api/edit.js @@ -1 +1,68 @@ // Edit Profile Route +const express = require('express') +const router = express.Router() +const { ensureAuth } = require('../../middleware/auth') + +const User = require('../../models/User.js'); +const { id } = require('date-fns/locale'); +const { last } = require('lodash'); + + + +// @desc Show edit page +// @route GET /edit/:id +router.get("/:id", ensureAuth, (req, res) => { + let avatar = req.user.image; + let curruser = req.user; + let firstName = req.user.firstName; + let lastName = req.user.lastName; + let email = req.user.email; + let googleId = req.user.googleId; + let _id = req.user._id; + + console.log(avatar); + + + res.status(200).render("edit", { + layout: "layouts/app", + avatar, + firstName, + lastName, + email, + googleId, + _id, + href: "/edit", + }); +}); + +router.put("/:id", ensureAuth, async(req, res) => { + try { + + let curruser1 = await User.findById(req.params.id).lean(); + + curruser1.firstName = req.body.firstName; + curruser1.lastName = req.body.lastName; + curruser1.email = req.body.email; + curruser1.displayName = curruser1.firstName + " " + curruser1.lastName + + console.log(curruser1.firstName + "this is the first name"); + console.log(curruser1.lastName + "this is the last name"); + console.log(curruser1.displayName + "this is the disply name"); + console.log(curruser1.email + "this is the email"); + curruser1 = await User.findOneAndUpdate({ _id: req.params.id }, { + firstName: curruser1.firstName, + lastName: curruser1.lastName, + email: curruser1.email, + displayName: curruser1.displayName, + }, { + new: true, // it will create a new one, if it doesn't exist + runValidators: true, // it check weather the fields are valid or not + }); + res.redirect("/portfolio"); + } catch (err) { + console.error(err) + return res.render('error/500') + } +}); + +module.exports = router; \ No newline at end of file diff --git a/views/edit.ejs b/views/edit.ejs index c5b1623..2b0d5c2 100644 --- a/views/edit.ejs +++ b/views/edit.ejs @@ -1 +1,97 @@ -

Edit Profile

+ +
+
+ + +
+ Edit Profile +
+ +
+ + + + +
+ +
+
+ +
+
+ + +
+
+
+
+ +
+
+ + +
+
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/views/partials/_nav.ejs b/views/partials/_nav.ejs index 34738a9..912c2f7 100644 --- a/views/partials/_nav.ejs +++ b/views/partials/_nav.ejs @@ -1,18 +1,15 @@ -
+
-
-
- -
-

- -

- -
+
-
+ + + \ No newline at end of file From e33eff8def9dfe49981eae5c520f7b36ebfbfd98 Mon Sep 17 00:00:00 2001 From: garimasingh22 <44470092+garimasingh22@users.noreply.github.com> Date: Thu, 27 Aug 2020 21:09:34 +0530 Subject: [PATCH 2/2] fixed bugs --- public/css/tailwind.css | 119 +++++++++++++++++++++++----------------- routes/api/edit.js | 22 +++----- views/edit.ejs | 51 +++-------------- views/partials/_nav.ejs | 16 ++++-- 4 files changed, 98 insertions(+), 110 deletions(-) diff --git a/public/css/tailwind.css b/public/css/tailwind.css index 629c605..ae78dff 100644 --- a/public/css/tailwind.css +++ b/public/css/tailwind.css @@ -1,107 +1,124 @@ @tailwind base; + /* Custom CSS */ + + /* Main CSS */ html, body { - margin: 0; - padding: 0; - width: 100%; - height: 100%; - overflow-x: hidden; - box-sizing: border-box; - background-color: rgb(226, 232, 240); + margin: 0; + padding: 0; + width: 100%; + height: 100%; + overflow-x: hidden; + box-sizing: border-box; + background-color: rgb(226, 232, 240); } .chartjs-container { - position: relative; - margin: auto; - height: 75vh; - width: 75vw; + position: relative; + margin: auto; + height: 75vh; + width: 75vw; } .tradebyte-logo { - color: #1955e4; - text-shadow: 1px 2px 40px rgba(0, 0, 0, 0.5); + color: #1955e4; + text-shadow: 1px 2px 40px rgba(0, 0, 0, 0.5); } .line { - border: 1.5px solid #8e9aad; + border: 1.5px solid #8e9aad; } .user-profile { - border-radius: 100px; - border: 10px solid #1955e4; - width: 130px; - height: 130px; + border-radius: 100px; + border: 10px solid #1955e4; + width: 130px; + height: 130px; } .tick { - height: 22px; - width: 22px; - border-radius: 50%; - background-color: #38cda0; - color: white; + height: 22px; + width: 22px; + border-radius: 50%; + background-color: #38cda0; + color: white; } .tick-background { - background: #a9f7e6; - border-radius: 29px; - color: #1b9b7f; + background: #a9f7e6; + border-radius: 29px; + color: #1b9b7f; } .tab-color { - border-radius: 10px; - border-color: #1955e4; - color: #1955e4; + border-radius: 10px; + border-color: #1955e4; + color: #1955e4; } .view-link { - color: #1955e4; + color: #1955e4; } .view-link:hover { - color: #0d338a; + color: #0d338a; } .button { - background-color: #1955e4; + background-color: #1955e4; } .button:hover { - background-color: #0d338a; + background-color: #0d338a; } .table-content { - overflow: scroll; - overflow-x: scroll; - overflow-y: auto; + overflow: scroll; + overflow-x: scroll; + overflow-y: auto; } .transaction-companySymbol { - color: rgb(0, 0, 0); - font-weight: 700; - font-size: 1.1rem; + color: rgb(0, 0, 0); + font-weight: 700; + font-size: 1.1rem; } -@tailwind components; - .symbolicon { - font-size: 72px; - background: -webkit-linear-gradient(#eee, #333); - background-clip: text; - -webkit-background-clip: text; - -webkit-text-fill-color: transparent; + font-size: 72px; + background: -webkit-linear-gradient(#eee, #333); + background-clip: text; + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; } .min-w { - min-width: 400px; + min-width: 400px; +} + +.notification { + position: relative; + display: inline-block; +} + +.notification .badge { + position: absolute; + top: -10px; + right: -10px; + padding: 5px 2px; + border-radius: 50%; + background-color: #1955e4; + color: white; } @media (max-width: 400px) { - .min-w { - min-width: 300px; - } + .min-w { + min-width: 300px; + } } -@tailwind utilities; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/routes/api/edit.js b/routes/api/edit.js index eb4944e..77162a7 100644 --- a/routes/api/edit.js +++ b/routes/api/edit.js @@ -11,14 +11,13 @@ const { last } = require('lodash'); // @desc Show edit page // @route GET /edit/:id -router.get("/:id", ensureAuth, (req, res) => { +router.get("/", ensureAuth, (req, res) => { let avatar = req.user.image; - let curruser = req.user; + let firstName = req.user.firstName; let lastName = req.user.lastName; let email = req.user.email; - let googleId = req.user.googleId; - let _id = req.user._id; + console.log(avatar); @@ -29,27 +28,23 @@ router.get("/:id", ensureAuth, (req, res) => { firstName, lastName, email, - googleId, - _id, href: "/edit", }); }); -router.put("/:id", ensureAuth, async(req, res) => { +router.put("/", ensureAuth, async(req, res) => { try { - let curruser1 = await User.findById(req.params.id).lean(); + + let curruser1 = await User.findById(req.user._id).lean(); + console.log(curruser1); curruser1.firstName = req.body.firstName; curruser1.lastName = req.body.lastName; curruser1.email = req.body.email; curruser1.displayName = curruser1.firstName + " " + curruser1.lastName - console.log(curruser1.firstName + "this is the first name"); - console.log(curruser1.lastName + "this is the last name"); - console.log(curruser1.displayName + "this is the disply name"); - console.log(curruser1.email + "this is the email"); - curruser1 = await User.findOneAndUpdate({ _id: req.params.id }, { + curruser1 = await User.findOneAndUpdate({ _id: curruser1._id }, { firstName: curruser1.firstName, lastName: curruser1.lastName, email: curruser1.email, @@ -58,6 +53,7 @@ router.put("/:id", ensureAuth, async(req, res) => { new: true, // it will create a new one, if it doesn't exist runValidators: true, // it check weather the fields are valid or not }); + res.redirect("/portfolio"); } catch (err) { console.error(err) diff --git a/views/edit.ejs b/views/edit.ejs index 2b0d5c2..3f6dd06 100644 --- a/views/edit.ejs +++ b/views/edit.ejs @@ -1,33 +1,3 @@ -
@@ -42,7 +12,7 @@ -
+