dongshuo2752 2016-06-05 16:54
浏览 66

Yii2简单授权,1个角色

I've got a project where you can register, login, and upload a photo with description and name after logging in. I've used Access Control filters, so only registered users can upload and edit photos.

The problem is that every registered user can change the photo's description and name, even if they did not uploaded it.

How can I ensure users can only edit the description of their own photos?

In the yii2 doc I saw RBAC, but I don't think, that I need RBAC, because I don't need a lot of roles.

I need only 1 role and my project is too simple for using a RBAC. I also thought that I can execute a loop, where I can check if user owns a photo, but I don't think that it is a good practice.

  • 写回答

1条回答 默认 最新

  • dqwh2717 2016-06-06 16:02
    关注

    I'm assuming you have a table and a model with all the uploaded images's data. I would recomend you add the BlameableBehavior in that model and add the created_by and updated_by attributes (or configure custom ones).

    After that, before you run any actionUpdate() and actionDelete() you could check if the current user's id is the same as the creator.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程