Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. public function SignUpAction(Request $request)
  2. {
  3. $user = new User();
  4. $em = $this->getDoctrine()->getManager();
  5. $form = $this->createForm(SignUpType::class, $user);
  6.  
  7. $form->handleRequest($request);
  8.  
  9. if ($form->isSubmitted() && $form->isValid()) {
  10.  
  11. $newUser = $form->getData();
  12. $password = $this->get('security.password_encoder')
  13. ->encodePassword($user, $newUser->getPassword());
  14. $user->setSalt(md5(time()));
  15. $user->setPassword($password);
  16. $user->setIsActive(true);
  17. $user->setEmail($newUser->getEmail());
  18. $user->setUsername($newUser->getUsername());
  19. $user->setStatus(true);
  20.  
  21. $role = $em->getRepository('AppBundle:Role')
  22. ->findByName('ROLE_ADMIN');
  23. $user->getUserRoles()->add($role);
  24. $em->persist($user);
  25. $em->flush();
  26.  
  27. return $this->redirectToRoute('AppBundle_homepage');
  28.  
  29. }
  30.  
  31.  
  32. return $this->render('AppBundle:Security:signup.html.twig', array(
  33. 'form' => $form->createView()
  34. ));
  35. }
  36.  
  37. [2016-09-08 18:30:49] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): Bad credentials. at /var/www/symfony.first/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php:90, Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): The presented password is invalid. at /var/www/symfony.first/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php:67)"} []
  38.  
  39. $token = new UsernamePasswordToken($user, $user->getPassword(), "main", $user->getRoles());
  40. $this->get("security.token_storage")->setToken($token);
  41.  
  42. $event = new InteractiveLoginEvent($request, $token);
  43. $this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
  44.  
  45. security:
  46. encoders:
  47. AppAppBundleEntityUser:
  48. algorithm: sha512
  49. encode-as-base64: true
  50. iterations: 10
  51.  
  52. providers:
  53. main:
  54. entity: { class: AppBundle:User, property: username }
  55.  
  56. firewalls:
  57. main:
  58. pattern: /.*
  59. form_login:
  60. check_path: /login_check
  61. login_path: /login/
  62. logout: true
  63. security: true
  64. anonymous: true
  65. remember_me:
  66. secret: '%secret%'
  67. lifetime: 604800 # 1 week in seconds
  68. path: /
  69. # by default, the feature is enabled by checking a
  70. # checkbox in the login form (see below), uncomment the
  71. # following line to always enable it.
  72. #always_remember_me: true
  73.  
  74. access_control:
  75. - { path: /admin/.*, role: ROLE_ADMIN }
  76. - { path: ^/login/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  77. - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement