symfony - FOS User Bundle: access other user profile: "This user does not have access to this section." -
i trying set simple action member details of other members of website; controller @ moment:
public function modalprofileaction($id) { $usermanager = $this->get('fos_user.user_manager'); $user = $usermanager->finduserby(array('id' => $id)); if (!is_object($user) || !$user instanceof userinterface) { throw new accessdeniedexception('this user not have access section.'); } return $this->render('testuserbundle:profile:modal_short_profile.html.twig', array( 'user' => $user )); }
this action triggered js (ajax method get). routing is:
test_user_modal: pattern: /team-member/{id} defaults: { _controller: testuserbundle:user:modalprofile } methods: [get] requirements: id: \d+
i geeting follwong error: "this user not have access section." there way around that? using wrong method or there security issue should include? ideas welcome
1)if want current logged in user , must use code user data:
$current_user=$this->getuser();
for example if want id , username of current user can use this:
$id=$current_user->getid(); $username=$current_user->getusername();
2) if want user information in admin panel , must use repository informations:
public function showaction($id) { $em = $this->getdoctrine()->getmanager(); $entity = $em->getrepository('userbundle:user')->find($id); if (!$entity) { throw $this->createnotfoundexception('unable find user entity.'); } return $this->render('userbundle:user:show.html.twig', array( 'entity' => $entity, )); }
i hope u!
Comments
Post a Comment