Как запретить пользователям просматривать другие публикации пользователей? - PullRequest
0 голосов
/ 01 апреля 2019

Я пытаюсь скрыть данные от других пользователей, когда они получают доступ к странице списка.Пользователь может видеть только свои данные для удаления или редактирования.

Я пользуюсь паспортом, экспресс-рулем, парсером, мангустом.

List.hbs:

<table class="table table-hover" style="overflow-x:auto;">
    <thead>
        <tr>
            <th>Description </th>
            <th>Price</th>
            <th>Seller</th>
            <th>Picture</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        {{#each list }}
        <tr>
            <td>{{this.product_name}}</td>
            <td>{{this.description}}</td>
            <td>€ {{this.price}}</td>
            <td> {{seller}} </td>
            <td>{{this.imagePath}}</td>
            <td>
                <a href="/product/{{this._id}}" class="text-info">
                <i class="far fa-edit"></i>edit</a>
                <a href="/product/delete/{{this._id}}" onclick="return confirm('Are you sure to delete this record?')"  class="text-danger"><i class="far fa-trash-alt"></i>Delete</a>
            </td>
            {{/each}}
        </tr>
        {{/if}}
    </tbody>
</table>
</div>

// Route // product.controller 
var User = require('../models/user');
var Product = require('../models/product');
var mongoose = require('mongoose');



router.get('/:id', isLoggedIn,  function(req, res){
  Product.findById(req.params.id, function(err, product){
   if(err){
    return res.write('Error');
}
   res.render("product/product", {
      viewTitle: "Update Product",
      product:product,
      seller: user.email
   });
 });
});
});

//Route list

router.get('/list', (req, res) =>{

 Product.find((err, docs)=>{
   if(!err){
    res.render('product/list', {
    list: docs
 });
}
   else{
     console.log('Error in retrieving product list: ' +err);
   }
 });
});

Я ожидаю отобразить только список от своего пользователя и скрыть от других пользователей.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...