Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function SignUpAction(Request $request)
- {
- $user = new User();
- $em = $this->getDoctrine()->getManager();
- $form = $this->createForm(SignUpType::class, $user);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $newUser = $form->getData();
- $password = $this->get('security.password_encoder')
- ->encodePassword($user, $newUser->getPassword());
- $user->setSalt(md5(time()));
- $user->setPassword($password);
- $user->setIsActive(true);
- $user->setEmail($newUser->getEmail());
- $user->setUsername($newUser->getUsername());
- $user->setStatus(true);
- $role = $em->getRepository('AppBundle:Role')
- ->findByName('ROLE_ADMIN');
- $user->getUserRoles()->add($role);
- $em->persist($user);
- $em->flush();
- return $this->redirectToRoute('AppBundle_homepage');
- }
- return $this->render('AppBundle:Security:signup.html.twig', array(
- 'form' => $form->createView()
- ));
- }
- [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)"} []
- $token = new UsernamePasswordToken($user, $user->getPassword(), "main", $user->getRoles());
- $this->get("security.token_storage")->setToken($token);
- $event = new InteractiveLoginEvent($request, $token);
- $this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
- security:
- encoders:
- AppAppBundleEntityUser:
- algorithm: sha512
- encode-as-base64: true
- iterations: 10
- providers:
- main:
- entity: { class: AppBundle:User, property: username }
- firewalls:
- main:
- pattern: /.*
- form_login:
- check_path: /login_check
- login_path: /login/
- logout: true
- security: true
- anonymous: true
- remember_me:
- secret: '%secret%'
- lifetime: 604800 # 1 week in seconds
- path: /
- # by default, the feature is enabled by checking a
- # checkbox in the login form (see below), uncomment the
- # following line to always enable it.
- #always_remember_me: true
- access_control:
- - { path: /admin/.*, role: ROLE_ADMIN }
- - { path: ^/login/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement