Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony] Automatyczne logowanie po rejestracji
mundeck
post 18.12.2017, 21:49:12
Post #1





Grupa: Zarejestrowani
Postów: 43
Pomógł: 0
Dołączył: 2.09.2012

Ostrzeżenie: (0%)
-----


Jak w Symfony 3.4 zrobić, aby użytkownik był automatycznie zalogowany po rejestracji? Do tej pory miałem tak, że przekierowywało na stronę logowania, ale w wielu serwisach dla wygody użytkownika jednak stosuje się automatyczne logowanie.
Próbuję to zrobić przez utworzenie i zapisanie nowego tokena.

Moja metoda rejestrująca wygląda tak:

  1. public function registerAction()
  2. {
  3. /** @var Request $request */
  4. $request = $this->get('request_stack')->getCurrentRequest();
  5.  
  6. $registerHelper = $this->get('app.helper.app.register');
  7.  
  8. $formData = $registerHelper->createFormData();
  9.  
  10. $form = $this->createForm(RegistrationType::class, $formData, [
  11. 'validation_groups' => ['registration']
  12. ]);
  13.  
  14. $form->handleRequest($request);
  15.  
  16. if($request->getMethod() == 'POST' && $form->isValid())
  17. {
  18. /** @var User $user */
  19. $user = $registerHelper->processForm($formData);
  20.  
  21.  
  22. /** @var TokenStorageInterface $tokenStorage */
  23. $tokenStorage = $this->get('security.token_storage');
  24.  
  25. $token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
  26.  
  27. $tokenStorage->setToken($token);
  28.  
  29. if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY'))
  30. {
  31. return $this->redirect($this->generateUrl('customer_index'));
  32. }
  33.  
  34. return $this->redirectToRoute('app_login');
  35.  
  36. }
  37.  
  38. return $this->render('AppBundle:homepage:register.html.twig', [
  39. 'form' => $form->createView(),
  40. ]);
  41. }


Niestety zwraca mi 500. Jak wywalę to isGranted() - to samo.

Ten post edytował mundeck 18.12.2017, 21:50:31
Go to the top of the page
+Quote Post
aras785
post 22.12.2017, 00:09:27
Post #2





Grupa: Zarejestrowani
Postów: 859
Pomógł: 177
Dołączył: 29.10.2009

Ostrzeżenie: (0%)
-----


Cześć.

Sprawdź tu:
https://stackoverflow.com/questions/5886713...-authentication
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.04.2024 - 15:44