当其他用户访问列表页面时,我正试图向他们隐藏数据。用户只能看到要删除或编辑的数据。
我正在使用护照,快速车把,人体分析器,猫鼬。
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);
}
});
});
我希望仅显示自己用户的列表,而对其他用户隐藏。