Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF]Symfony 3 - autentykacja
wiciu010
post
Post #1





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

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


Próbuję zrobić logowanie użytkowników zgodnie z opisem http://symfony.com/doc/current/cookbook/se...y_provider.html

Niestety nijak mi to nie idzie.

Entity User.php mam zrobione jak w przykładzie. Tak samo baze danych. Próbowałem hasła trzymać jako bcrypt, md5 oraz plaintext i nic nie działa.

Plik security.yml

Kod
security:
    encoders:
        AppBundle\Entity\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       [ROLE_USER]

    providers:
        our_db_provider:
            entity: { class: AppBundle:User, property: username }

    firewalls:
        main:
            pattern:    ^/
            anonymous: ~
            provider: our_db_provider

            form_login:
                login_path: /
                check_path: /
            logout:
                 path:   /logout
                 target: /

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }


W formularzu przekazuję zmienne jako _username oraz _password czyli zgodnie z dokumentacją.

Kontroler do obsługi:

  1. public function indexAction(Request $request)
  2. {
  3. $session = $request->getSession();
  4.  
  5. $authenticationUtils = $this->get('security.authentication_utils');
  6.  
  7. $error = $authenticationUtils->getLastAuthenticationError();
  8.  
  9. $lastUsername = $authenticationUtils->getLastUsername();
  10.  
  11. if ($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')){
  12. return $this->redirect($this->generateUrl('admin_dashboard'));
  13. }
  14.  
  15. return $this->render('default/index.html.twig', [
  16. 'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
  17. 'body_id' => "simple-page",
  18. 'last_username' => $lastUsername,
  19. 'error' => $error
  20. ]);
  21. }


Jak podam błędne dane do logowania to otrzymuję
Kod
exception 'Symfony\Component\Security\Core\Exception\BadCredentialsException' with message 'Bad credentials.'


Jak podam poprawne to nie przekierowuje mnie do admin_dashboard i nie zwraca żadnego błędu. W debugu dalej jestem jako anonymous

W bazie mam rolę ROLE_ADMIN i takie też mam w getRoles zwracane w entity User.

Co jest nie tak?
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 4.10.2025 - 22:30