Bonsoir,
j'utilise dans mon projet le bundle FOsUserBundle qui permet la gestion des utilisateurs.
Lorsque je m'authentifie sur monsite/login il me renvoie sur la page : monsite/login_check
sur laquelle il y a ma page d'accueil mais si je l'actualise j'ai l'erreur suivant :
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 configurationYou 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.');
}
- 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 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 form_login: login_path: fos_user_security_login check_path: fos_user_security_check
Je vous montré tous les configurations pour devenir être claire.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 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
-app/config/routing.yml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 # 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 use_listener: false
-app/config/security.yml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 fos_user: resource: "@FOSUserBundle/Resources/config/routing/all.xml"
- Mon contrôleur "SecurityController ":
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 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: ^/ form_login: login_path: fos_user_security_login check_path: fos_user_security_check provider: fos_userbundle csrf_provider: form.csrf_provider remember_me: true remember_me: key: %secret% lifetime: 604800 path: / domain: ~ user_provider: fos_userbundle #csrf_token_generator: security.csrf.token_manager # if you are using Symfony < 2.8, use the following config instead: # csrf_provider: form.csrf_provider logout: true anonymous: true login: pattern: ^/login$ security: false access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/, role: ROLE_ADMIN }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 <?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:
- dans le config.yml de mon UserBundle j'ai ajouté çà;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 class ManagementUserBundle extends Bundle { public function getParent() { return 'FOSUserBundle'; } }
- Ma vue "login" de mon Bundle userBundle:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 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 }
Pouvez-vous m'aider? merci beaucoup
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 <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>
Partager