Просмотр исходного кода

Prevent password from being passed to front end

Lee Morgan 6 лет назад
Родитель
Сommit
24d99d9f88
2 измененных файлов с 5 добавлено и 1 удалено
  1. 1 0
      controllers/merchantData.js
  2. 4 1
      controllers/renderer.js

+ 1 - 0
controllers/merchantData.js

@@ -67,6 +67,7 @@ module.exports = {
                             .then((newMerchant)=>{
                                 newMerchant.populate("recipes.ingredients.ingredient").execPopulate()
                                     .then((newestMerchant)=>{
+                                        merchant.password = undefined;
                                         return res.json({merchant: newestMerchant, count: result.data.elements.length});
                                     })
                                     .catch((err)=>{

+ 4 - 1
controllers/renderer.js

@@ -9,7 +9,7 @@ const token = "b48068eb-411a-918e-ea64-52007147e42c";
 module.exports = {
     //GET - Shows the public landing page
     //Returns: 
-    //  Error: a single error message
+    //  Error: a single error message (only if there is an error)
     //Renders landingPage
     landingPage: function(req, res){
         let error = {};
@@ -69,6 +69,7 @@ module.exports = {
 
                             merchant.save()
                                 .then((updatedMerchant)=>{
+                                    merchant.password = undefined;
                                     res.render("inventoryPage/inventory", {merchant: updatedMerchant});
                                     Transaction.create(transactions);
                                     return;
@@ -82,6 +83,7 @@ module.exports = {
                             console.log(err);
                         });
                 }else if(merchant.pos === "none"){
+                    merchant.password = undefined;
                     return res.render("inventoryPage/inventory", {merchant: merchant})
                 }else{
                     return res.redirect("/");
@@ -154,6 +156,7 @@ module.exports = {
             })
             .populate("inventory.ingredient")
             .then((merchant)=>{
+                merchant.password = undefined;
                 return res.render("recipesPage/recipes", {merchant: merchant});
             })
             .catch((err)=>{