Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public function addroleAction($role) {
  2. $securityContext = $this->get('security.context');
  3. $em = $this->getDoctrine()->getManager();
  4. $user = $this->get('security.context')->getToken()->getUser();
  5. $userId = $user->getId();
  6. $userObj = $em->getRepository('ProjectEntityBundle:User')->find($userId);
  7.  
  8. switch ($role) {
  9. case 6://student
  10. $userObj->addRole('ROLE_STUDENT');
  11. $em->flush();
  12. $securityContext->getToken()->setUser($userObj);
  13. break;
  14. }
  15. return $this->redirect($this->generateUrl('check_role'));
  16. }
  17.  
  18. public function checkroleAction() {
  19.  
  20. $securityContext = $this->get('security.context');
  21. if ($securityContext->isGranted('ROLE_STUDENT')) {
  22. return $this->redirect($this->generateUrl('student_profile'));
  23. } else {
  24. return $this->render('ProjectEduBundle:User:selectrole.html.twig');
  25. }
  26. }
  27.  
  28. $this->get('security.context')->getToken()->setUser($userObject);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement