Bonjour,

pour la gestion des utilisateurs j'utilise le Bundle : FOsUserBundle .
Lorsque je m'authentifie sur 127.0.0.1/login il me renvoie sur la page : 127.0.0.1/login_check
sur laquelle il y a ma page d'accueil mais si je l'actualise j'ai l'erreur suivant :

You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.
500 Internal Server Error - RuntimeException
//Stack Trace
// l'erreur dans mon contrôleur que j'ai crée 
in src/Management/UserBundle/Controller/SecurityController.php at line 79 -
public function checkAction()
{
79--> throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

Donc il demande de configurer le check path au sein le form_login dans le fichier security.yml . Aprés une recherche sur l'internet je trouve cette configuration:

login_path: fos_user_security_login
check_path: fos_user_security_check

Ce que je fais

Pour avoir si j'ai bien les routes de FosUserBundle , j'ai exécuté cette commande php app/console router:debug et voilà ce que j'ai :

fos_user_profile_show             GET         ANY    ANY  /profile/                         
 fos_user_profile_edit             GET|POST    ANY    ANY  /profile/edit                     
 fos_user_registration_register    GET|POST    ANY    ANY  /register/                        
 fos_user_registration_check_email GET         ANY    ANY  /register/check-email             
 fos_user_registration_confirm     GET         ANY    ANY  /register/confirm/{token}         
 fos_user_registration_confirmed   GET         ANY    ANY  /register/confirmed               
 fos_user_resetting_request        GET         ANY    ANY  /resetting/request                
 fos_user_resetting_send_email     POST        ANY    ANY  /resetting/send-email             
 fos_user_resetting_check_email    GET         ANY    ANY  /resetting/check-email            
 fos_user_resetting_reset          GET|POST    ANY    ANY  /resetting/reset/{token}          
 fos_user_change_password          GET|POST    ANY    ANY  /change-password/change-password  
 fos_user_security_login           ANY         ANY    ANY  /login                            
 fos_user_security_check           ANY         ANY    ANY  /login_check                      
 fos_user_security_logout          ANY         ANY    ANY  /logout

-app/config/config.yml

# config fosUser:
fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    from_email:
         address:        admin@gmail.com
         sender_name:    admin
    registration:
           confirmation:
               enabled:    true
    user_class: Management\UserBundle\Entity\User

-app/config/routing.yml

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

-app/config/security.yml

# app/config/security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
       ROLE_MANAGER:       [ROLE_USER]
       ROLE_ADMIN: [ROLE_MANAGER, ROLE_ALLOWED_TO_SWITCH]

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        dev:
          pattern:  ^/(_(profiler|wdt)|css|images|js)/
          security: false
        default:
            anonymous: ~

        main:
            pattern: ^/
            anonymous: true
            form_login:
                 csrf_provider: form.csrf_provider
                 login_path: fos_user_security_login
                 check_path: fos_user_security_check
                 #provider: fos_userbundle
                 #default_target_path: index
                 #always_use_default_target_path: true
                 #use_referer: true
                 #target_path_parameter: redirect_url
                 #failure_path: login_failure
                 remember_me: true
            remember_me:
                key:         %secret%
                lifetime: 604800
                path:     /

            logout:
                  path:   fos_user_security_logout
                  target: /login
  • Mon contrôleur "SecurityController ":
<?php

namespace Management\UserBundle\Controller;

use Symfony\Component\Security\Core\SecurityContext;
use FOS\UserBundle\Controller\SecurityController as BaseController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Event\UserEvent;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\Security\Core\Security;

class SecurityController extends Controller{

    public function loginAction(Request $request)
    {
        /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
        $session = $request->getSession();

        if (class_exists('\Symfony\Component\Security\Core\Security')) {
            $authErrorKey = Security::AUTHENTICATION_ERROR;
            $lastUsernameKey = Security::LAST_USERNAME;
        } else {
            // BC for SF < 2.6
            $authErrorKey = SecurityContextInterface::AUTHENTICATION_ERROR;
            $lastUsernameKey = SecurityContextInterface::LAST_USERNAME;
        }

        // get the error if any (works with forward and redirect -- see below)
        if ($request->attributes->has($authErrorKey)) {
            $error = $request->attributes->get($authErrorKey);
        } elseif (null !== $session && $session->has($authErrorKey)) {
            $error = $session->get($authErrorKey);
            $session->remove($authErrorKey);
        } else {
            $error = null;
        }

        if (!$error instanceof AuthenticationException) {
            $error = null; // The value does not come from the security component.
        }

        // last username entered by the user
        $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);

        if ($this->has('security.csrf.token_manager')) {
            $csrfToken = $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue();
        } else {
            // BC for SF < 2.4
            $csrfToken = $this->has('form.csrf_provider')
                ? $this->get('form.csrf_provider')->generateCsrfToken('authenticate')
                : null;
        }

        return $this->renderLogin(array(
            'last_username' => $lastUsername,
            'error' => $error,
            'csrf_token' => $csrfToken,
        ));
    }

    protected function renderLogin(array $data)
    {
        return $this->render('ManagementUserBundle:Security:login.html.twig', $data);
    }

    public function checkAction()
    {
        throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
    }

    public function logoutAction()
    {
        throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
    }

}

-L'héritage de FosUser:

class ManagementUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}
  • dans le routing.yml de mon UserBundle j'ai ajouté çà;
fos_user_security_login:
        pattern:   /login
        defaults:  { _controller: FOSUserBundle:Security:login }

fos_user_security_check:
        pattern:   /login_check
        defaults:  { _controller: FOSUserBundle:Security:check }

fos_user_security_logout:
        pattern:   /logout
        defaults:  { _controller: FOSUserBundle:Security:logout }
  • Ma vue "login" de mon Bundle userBundle:

    <div class="panel-body">
    
            {% if error %}
                <div class="form-group text-center"><span class="text-danger">{{ error|trans({}, 'FOSUserBundle') }}</span></div>
            {% endif %}
    
            <form class="form-horizontal m-t-20" action="{{ path("fos_user_security_check") }}" method="post">
                <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
    
                <div class="form-group ">
                    <div class="col-xs-12">
                        <input class="form-control input-lg " type="text" id="username"
                           name="_username" value="{{ last_username }}" required="required" placeholder="Username">
                    </div>
                </div>
    
                <div class="form-group">
                    <div class="col-xs-12">
                        <input class="form-control input-lg" type="password" required="required"
                               name="_password"  placeholder="Password">
                    </div>
                </div>
    
                <div class="form-group ">
                    <div class="col-xs-12">
                        <div class="checkbox checkbox-primary">
                            <input id="checkbox-signup" type="checkbox" checked="checked" name="_remember_me" value="on" >
                            <label for="checkbox-signup">
                               Rester Connecté
                            </label>
                        </div>
    
                    </div>
                </div>
    
                <div class="form-group text-center m-t-40">
                    <div class="col-xs-12">
                        <button class="btn btn-primary btn-lg w-lg waves-effect waves-light" type="submit">Connexion</button>
                    </div>
                </div>
               <br>
                <div class="col-md-12">
                    <div class="col-sm-7">
                        <a href="{{ path('fos_user_resetting_request') }}"><i class="fa fa-lock m-r-5"></i>
                          <strong>Mot de passe oublié ? </strong>
                        </a>
                    </div>
                </div>
            </form>
        </div>

Pouvez-vous m'aider? merci beaucoup mes amis :)

3 réponses


emile01
Auteur
Réponse acceptée

j'ai trouvé la solution ;) , il faut mettre la route "fos_user_security" dans le routing.yml de mon UserBundle

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"
    prefix: /
emile01
Auteur

le FosUserBundle est bien installé chez moi car d'aprés l'exécution de la commande "php app/console route:debug" j'ai tous les routes de FodsuserBundle.

Pour répondre a ta question , j'ai réécris toutes les méthodes (loginAction, registerAction, checkAction) dans mon controller (SecurityController) car je dois modifié les vues selon mo template que j'ai intégré et aussi leur traitement.

-est ce qu'il est nécessaire de développer la fontion checkAction() de FosUserBundle ,non ? ou bien j'ai mis le fausse "route " dans ma vue ?

emile01
Auteur

D'accord je vais essayé comme ça je te remercie pour ton aide