简体   繁体   中英

How to give access to an update page to one particular user only?

I have a user entity and later I want to allow the users to update their details. I do this by sending to a route http://localhost:8000/update/ {id} I want to make this page to be accessed by that owner of the profile only. For an instance, if the user with the id 20 is logged in, he should have access to only http://localhost:8000/update/20 and should not allow to access someone else's. How to do this in symfony 4?

Furthermore, you can get the current logged in user by the following code. $this->get('security.token_storage')->getToken()->getUser();

Use session variables, so that it is unique only to the user and the user cannot access other user's pages. It is similar to the way in which when one user is logged in, he can't access other accounts. That is also done using session variables. Session variables in symfony

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM