Bonjour,
I'm starting with Symfony, and I'm trying to get users to see the profile of other users.
My profile template is the same for everyone, the display of information is based on the user name passed in parameters of the URL. I simply compare on twig if the username in session and the one in parameters correspond.
For exemple in my profil view:
{% if app.user.username == userAccount.username %}
My profile{% else %}
{{ userAccount.username }} profile{% endif %}
My index method for the route account:
public function index($username, UserRepository $repo, Request $request{
$user = $repo->findUserByUsername($username);
if (!$user){throw $this->createNotFoundException();}
I retrieve the user in BDD according to his username. The problem is that I really get everything back and I would like to know if it's secure? Can someone intercept the query in any way and see all the information retrieved?
I then create a password change page, the route always takes the username as a parameter. However this time, in my controller I indicated that it was necessary to redirect the user in the case where his user name in session was not identical to that to pass in parameters.
public function changePassword($username, Request $request, UserPasswordEncoderInterface $passwordEncoder, ObjectManager $manager, \Swift_Mailer $mailer){
$user = $this->getUser();
if ($username == null){
$username = $user->getUsername();}
if ($user->getUsername() !== $username){
throw $this->createNotFoundException();}}
Is this a sure way to verify that the user is the right one?
I do not know if my way of doing things is good, so if someone could enlighten me so that I can continue or adapt my work.
Thank you !