Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF][Symfony2][SF2]Autentykacja użytkownika i security.yml
webmaniak
post
Post #1





Grupa: Zarejestrowani
Postów: 371
Pomógł: 30
Dołączył: 14.04.2010

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


Witam,
Mam problem z plikiem security.yml i routingiem -tak sądzę. Poniżej plik security.yml
Kod
# you can read more about security in the related section of the documentation
# http://symfony.com/doc/current/book/security.html
security:
    # http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password
    encoders:
        Common\UserBundle\Entity\User:
            algorithm: bcrypt

    # http://symfony.com/doc/current/book/security.html#hierarchical-roles
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
        blog_users:
            entity:
                class: CommonUserBundle:User
                property: username

    # the main part of the security, where you can set up firewalls
    # for specific sections of your app
    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern:  ^/(_(profiler|wdt)|css|img|js)/
            security: false

        # secures part of the application
        blog_security:
            pattern:    ^/
            anonymous: ~
            form_login:
                check_path: _check_path
                login_path: _blog_login
                default_target_path: blog_index
            logout:
                path:   _logout
                target: blog_index
            #http_basic:
            #    realm: "Secured Demo Area"

    # with these settings you can restrict or allow access for different parts
    # of your application based on roles, ip, host or methods
    # http://symfony.com/doc/current/book/security.html#security-book-access-control-matching-options
    access_control:
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

routing.yml w CommonUserBundle:
Kod
common_user:
    resource: "@CommonUserBundle/Controller/"
    type:     annotation
    prefix:   /

_check_path:
    path: /login-check

_logout:
    path: /logout

Problem polega na tym że po kliku na "Zaloguj" następuje przekierowanie na ścieżkę lgon-check, co z kolei skutkuje wyświetleniem błędu:
  1. Unable to find the controller for path "/login-check". Maybe you forgot to add the matching route in your routing configuration?

Podpowiedzi które znalazłem do tej pory nie naprowadziły mnie niestety na rozwiązanie problemu. Od razu dodam że zapoznałem się ze stroną dokumentacji:
http://symfony.com/doc/current/book/securi...-authentication
Tyle tylko że nie potrafię przenieść opisu, który tam jest na mój kod ;/ jakieś sugestie co tutaj jest źle? Będę wdzięczny za pomoc i z góry dziękuję (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
webmaniak
post
Post #2





Grupa: Zarejestrowani
Postów: 371
Pomógł: 30
Dołączył: 14.04.2010

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


Cytat(prz3kus @ 3.03.2015, 20:26:32 ) *
webmaniak
Nic w tej metodzie nie trzeba zwracać, zainstaluj sobie czyste symfony i popatrz na przykład z bundla który jest domyślnie wbudowany, tam masz gotowca

Dzięki, dopiero teraz mam czas by znowu spróbować rozwiązać problem. Musiałem ja coś pomieszać w plikach i dlatego nie działa to tak jak powinno. Z pewnością podzielę się informacjami co było nie tak jak rozwiążę problem (IMG:style_emoticons/default/smile.gif)

Witam,
próbowałem, kombinowałem by na moim kodzie odpalić to logowanie - problem jest w sytuacji gdy używam entity user. Postanowiłem od podszewki poznać sposób autentykacji w symfony2. Zaczołem od:
http://symfony.com/doc/current/book/security.html
A po sekcji A) jest link do:
http://symfony.com/doc/current/cookbook/se...ogin_setup.html
Zacząłem robić wszystko zgodnie z tym opisem. Jednak po utworzeniu SecurityController i metod login i loginCheck, jak poniżej:
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5.  
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Request;
  8.  
  9. class SecurityController extends Controller
  10. {
  11.  
  12. /**
  13.   * @Route("/login", name="login_route")
  14.   */
  15. public function loginAction(Request $request)
  16. {
  17. $authenticationUtils = $this->get('security.authentication_utils');
  18.  
  19. // get the login error if there is one
  20. $error = $authenticationUtils->getLastAuthenticationError();
  21.  
  22. // last username entered by the user
  23. $lastUsername = $authenticationUtils->getLastUsername();
  24.  
  25. return $this->render(
  26. 'security/login.html.twig',
  27. // last username entered by the user
  28. 'last_username' => $lastUsername,
  29. 'error' => $error,
  30. )
  31. );
  32. }
  33.  
  34. /**
  35.   * @Route("/login_check", name="login_check")
  36.   */
  37. public function loginCheckAction()
  38. {
  39. // this controller will not be executed,
  40. // as the route is handled by the Security system
  41. }
  42. }

mam błąd w postaci:
Kod
FileLoaderImportCircularReferenceException in FileLoader.php line 97: Circular reference detected in "C:\xampp\htdocs\sf2\app/config/routing_dev.yml" ("C:\xampp\htdocs\sf2\app/config/routing_dev.yml" > "C:\xampp\htdocs\sf2\app/config\routing.yml" > "C:\xampp\htdocs\sf2\src\AppBundle/Controller/" > "C:\xampp\htdocs\sf2\app/config/routing_dev.yml").

    in FileLoader.php line 97
    at FileLoader->import('C:\xampp\htdocs\sf2\app/config/routing_dev.yml', null, false, 'C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml') in YamlFileLoader.php line 155
    at YamlFileLoader->parseImport(object(RouteCollection), array('resource' => 'C:\xampp\htdocs\sf2\app/config/routing_dev.yml'), 'C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml') in YamlFileLoader.php line 91
    at YamlFileLoader->load('C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 45
    at DelegatingLoader->load('C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 58
    at DelegatingLoader->load('C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'yaml') in classes.php line 3418
    at Router->getRouteCollection() in classes.php line 3388
    at Router->getGeneratorDumperInstance() in classes.php line 3369
    at Router->getGenerator() in classes.php line 3314
    at Router->generate('_profiler', array('token' => '558d6d')) in WebDebugToolbarListener.php line 66
    at WebDebugToolbarListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
    at call_user_func(array(object(WebDebugToolbarListener), 'onKernelResponse'), object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher)) in WrappedListener.php line 61
    at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher))
    at call_user_func(object(WrappedListener), object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) in classes.php line 3916
    at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent)) in classes.php line 3849
    at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in classes.php line 4010
    at ContainerAwareEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in TraceableEventDispatcher.php line 112
    at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in bootstrap.php.cache line 3046
    at HttpKernel->filterResponse(object(Response), object(Request), '2') in bootstrap.php.cache line 3041
    at HttpKernel->handleRaw(object(Request), '2') in bootstrap.php.cache line 2988
    at HttpKernel->handle(object(Request), '2', true) in bootstrap.php.cache line 3137
    at ContainerAwareHttpKernel->handle(object(Request), '2', true) in ExceptionListener.php line 58
    at ExceptionListener->onKernelException(object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher))
    at call_user_func(array(object(ExceptionListener), 'onKernelException'), object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher)) in WrappedListener.php line 61
    at WrappedListener->__invoke(object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher))
    at call_user_func(object(WrappedListener), object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher)) in classes.php line 3916
    at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 3849
    at EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 4010
    at ContainerAwareEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in TraceableEventDispatcher.php line 112
    at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in bootstrap.php.cache line 3058
    at HttpKernel->handleException(object(FileLoaderLoadException), object(Request), '1') in bootstrap.php.cache line 2994
    at HttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 3137
    at ContainerAwareHttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 2381
    at Kernel->handle(object(Request)) in app_dev.php line 28

Czy ktoś wie skąd on wynika i może mnie naprowadzić na rozwiązanie?
Z góry dziękuję (IMG:style_emoticons/default/smile.gif)

Edit:
Problem rozwiązany. Brakowało:
  1. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

Eh ;/

Ten post edytował webmaniak 4.04.2015, 16:16:06
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: 28.12.2025 - 16:27