Bonjour,
J'ai un problème avec mon authentification, j'ai suivi tout le tutoriel de la documentation : http://symfony.com/fr/doc/current/co..._provider.html
Mais sa me renvoi souvent bad credentials, alors je vous envoi tout ce qui vous faut si quelqu'un peut m'aider!
L'erreur est toujours la même : Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?
Merci!
Après des essais et encore des essais j'y suis enfin arrivé! Je laisse mon code pour ceux qui rencontrerais la même difficulté!
Bonne journée, et merci a stephan.78, pour sa patience, j'ai enfin réussi tout seul!^^
Voici ma classe Adherent:
Mon Controlleur:
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442 <?php namespace SymfonyCapsule\CapsuleBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use \Symfony\Component\Security\Core\User\UserInterface; /** * Adherent * * @ORM\Table(name="adherent") * @ORM\Entity * @ORM\Entity(repositoryClass="SymfonyCapsule\CapsuleBundle\Entity\AdherentRepository * @UniqueEntity(fields="pseudoAdherent", message="Ce pseudo existe déjà...") * @UniqueEntity(fields="mailAdherent", message="Ce courriel existe déjà...") * @UniqueEntity(fields="telAdherent", message="Ce telephone existe déjà...") * * * */ class Adherent implements UserInterface { /** * @var integer * * @ORM\Column(name="id_adherent", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $idAdherent; /** * @var string * * @ORM\Column(name="nom_adherent", type="string", length=32, nullable=false) */ private $nomAdherent; /** * @var string * * @ORM\Column(name="prenom_adherent", type="string", length=32, nullable=false) */ private $prenomAdherent; /** * @var string * * @ORM\Column(name="adresse_adherent", type="string", length=50, nullable=false) */ private $adresseAdherent; /** * @var string * * @ORM\Column(name="tel_adherent", type="string", length=16, nullable=false) */ private $telAdherent; /** * @var string * * @ORM\Column(name="mail_adherent", type="string", length=32, nullable=false) */ private $mailAdherent; /** * @var string * * @ORM\Column(name="cp_adherent", type="string", length=5, nullable=false) */ private $cpAdherent; /** * @var string * * @ORM\Column(name="ville_adherent", type="string", length=32, nullable=false) */ private $villeAdherent; /** * @var \DateTime * * @ORM\Column(name="anniv_adherent", type="date", nullable=false) */ private $annivAdherent; /** * @var \DateTime * * @ORM\Column(name="date_adherent", type="date", nullable=false) */ private $dateAdherent; /** * @var string * * @ORM\Column(name="pseudo_adherent", type="string", length=32, nullable=false) */ private $pseudoAdherent; /** * @var string * * @ORM\Column(name="mot_de_passe_adherent", type="string", length=32, nullable=false) */ private $motDePasseAdherent; /** * @var string * * @ORM\Column(name="photo_adherent", type="string", length=100, nullable=false) */ private $photoAdherent; /** * @inheritDoc */ public function getUsername() { return $this->pseudoAdherent; } /** * @inheritDoc */ public function getSalt() { return ''; } /** * @inheritDoc */ public function getPassword() { return $this->motDePasseAdherent; } /** * @inheritDoc */ public function getRoles() { return array('ROLE_USER'); } /** * @inheritDoc */ public function eraseCredentials() { } /** * Get idAdherent * * @return integer */ public function getIdAdherent() { return $this->idAdherent; } /** * Set nomAdherent * * @param string $nomAdherent * @return Adherent */ public function setNomAdherent($nomAdherent) { $this->nomAdherent = $nomAdherent; return $this; } /** * Get nomAdherent * * @return string */ public function getNomAdherent() { return $this->nomAdherent; } /** * Set prenomAdherent * * @param string $prenomAdherent * @return Adherent */ public function setPrenomAdherent($prenomAdherent) { $this->prenomAdherent = $prenomAdherent; return $this; } /** * Get prenomAdherent * * @return string */ public function getPrenomAdherent() { return $this->prenomAdherent; } /** * Set adresseAdherent * * @param string $adresseAdherent * @return Adherent */ public function setAdresseAdherent($adresseAdherent) { $this->adresseAdherent = $adresseAdherent; return $this; } /** * Get adresseAdherent * * @return string */ public function getAdresseAdherent() { return $this->adresseAdherent; } /** * Set telAdherent * * @param string $telAdherent * @return Adherent */ public function setTelAdherent($telAdherent) { $this->telAdherent = $telAdherent; return $this; } /** * Get telAdherent * * @return string */ public function getTelAdherent() { return $this->telAdherent; } /** * Set mailAdherent * * @param string $mailAdherent * @return Adherent */ public function setMailAdherent($mailAdherent) { $this->mailAdherent = $mailAdherent; return $this; } /** * Get mailAdherent * * @return string */ public function getMailAdherent() { return $this->mailAdherent; } /** * Set cpAdherent * * @param string $cpAdherent * @return Adherent */ public function setCpAdherent($cpAdherent) { $this->cpAdherent = $cpAdherent; return $this; } /** * Get cpAdherent * * @return string */ public function getCpAdherent() { return $this->cpAdherent; } /** * Set villeAdherent * * @param string $villeAdherent * @return Adherent */ public function setVilleAdherent($villeAdherent) { $this->villeAdherent = $villeAdherent; return $this; } /** * Get villeAdherent * * @return string */ public function getVilleAdherent() { return $this->villeAdherent; } /** * Set annivAdherent * * @param \DateTime $annivAdherent * @return Adherent */ public function setAnnivAdherent($annivAdherent) { $this->annivAdherent = $annivAdherent; return $this; } /** * Get annivAdherent * * @return \DateTime */ public function getAnnivAdherent() { return $this->annivAdherent; } /** * Set dateAdherent * * @param \DateTime $dateAdherent * @return Adherent */ public function setDateAdherent($dateAdherent) { $this->dateAdherent = $dateAdherent; return $this; } /** * Get dateAdherent * * @return \DateTime */ public function getDateAdherent() { return $this->dateAdherent; } /** * Set pseudoAdherent * * @param string $pseudoAdherent * @return Adherent */ public function setPseudoAdherent($pseudoAdherent) { $this->pseudoAdherent = $pseudoAdherent; return $this; } /** * Get pseudoAdherent * * @return string */ public function getPseudoAdherent() { return $this->pseudoAdherent; } /** * Set motDePasseAdherent * * @param string $motDePasseAdherent * @return Adherent */ public function setMotDePasseAdherent($motDePasseAdherent) { $this->motDePasseAdherent = $motDePasseAdherent; return $this; } /** * Get motDePasseAdherent * * @return string */ public function getMotDePasseAdherent() { return $this->motDePasseAdherent; } /** * Set photoAdherent * * @param string $photoAdherent * @return Adherent */ public function setPhotoAdherent($photoAdherent) { $this->photoAdherent = $photoAdherent; return $this; } /** * Get photoAdherent * * @return string */ public function getPhotoAdherent() { return $this->photoAdherent; } }
Ma page security.yml:
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 <?php namespace SymfonyCapsule\CapsuleBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use SymfonyCapsule\CapsuleBundle\Entity\Adherent; use SymfonyCapsule\CapsuleBundle\Form\AdherentType; use SymfonyCapsule\CapsuleBundle\Entity\Capsule; use SymfonyCapsule\CapsuleBundle\Form\CapsuleType; use Symfony\Component\Security\Core\SecurityContext; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; class DefaultController extends Controller { public function indexAction() { return $this->render('SymfonyCapsuleCapsuleBundle:Default:index.html.twig'); } public function inscriptionAction() { $em = $this->getDoctrine()->getEntityManager(); $a = new Adherent(); $form = $this->createForm(new AdherentType(), $a); $request = $this->getRequest(); if ($request->isMethod('POST')) { $form->bindRequest($request); if ($form->isValid()) { $a = $form->getData(); $em->persist($a); $em->flush(); return $this->redirect($this->generateUrl("symfony_capsule_capsule_homepage")); } } return $this->render('SymfonyCapsuleCapsuleBundle:Default:inscription.html.twig', array( 'form' => $form->createView(), )); } public function voirAction() { $em = $this->getDoctrine()->getEntityManager(); $capsule = $em->getRepository("SymfonyCapsuleCapsuleBundle:Capsule")->findAll(); return $this->render('SymfonyCapsuleCapsuleBundle:Default:voir.html.twig', array( 'capsules' => $capsule, )); } public function detailAction(Capsule $capsule) { return $this->render('SymfonyCapsuleCapsuleBundle:Default:detail.html.twig', array( 'capsule' => $capsule, )); } public function ajouterAction() { $em = $this->getDoctrine()->getEntityManager(); $a = new Capsule(); $form = $this->createForm(new CapsuleType(), $a); $request = $this->getRequest(); if ($request->isMethod('POST')) { $form->bindRequest($request); if ($form->isValid()) { $maison = $em->getRepository('SymfonyCapsuleCapsuleBundle:Maison')->find($a->getIdMaison()); $a->setIdMaison($maison); //$a = $form->getData(); //var_dump($form->getData()); //exit; //$a->setIdMaison($) == ''; $em->persist($a); $em->flush(); return $this->redirect($this->generateUrl("symfony_capsule_capsule_index")); } } return $this->render('SymfonyCapsuleCapsuleBundle:Default:ajouter.html.twig', array( 'form' => $form->createView(), )); } public function loginAction() { $request = $this->getRequest(); $session = $request->getSession(); // get the login error if there is one if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); } else { $error = $session->get(SecurityContext::AUTHENTICATION_ERROR); $session->remove(SecurityContext::AUTHENTICATION_ERROR); } return $this->render('SymfonyCapsuleCapsuleBundle:Default:login.html.twig', array( // last username entered by the user 'last_username' => $session->get(SecurityContext::LAST_USERNAME), 'error' => $error, )); } public function profilAction() { //$em = $this->getDoctrine()->getEntityManager(); $user=$this->getRequest()->getUser(); $id=$this->get($user); return new response($id); //$profil = $em->getRepository("SymfonyCapsuleCapsuleBundle:Adherent")->find($id); return $this->render('SymfonyCapsuleCapsuleBundle:Default:profil.html.twig', array( // 'profil' => $profil, )); } }
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 security: encoders: SymfonyCapsule\CapsuleBundle\Entity\Adherent: plaintext role_hierarchy: ROLE_ADMIN: ROLE_USER providers: administrators: entity: { class: SymfonyCapsuleCapsuleBundle:Adherent, property: pseudoAdherent } firewalls: login_firewall: pattern: ^/caps/login$ anonymous: ~ inscription_firewall: pattern: ^/caps/inscription anonymous: ~ secured_area: pattern: ^/caps/* form_login: check_path: /caps/login_check login_path: /caps/login username_parameter: pseudoAdherent password_parameter: motDePasseAdherent logout: path: /caps/logout access_control: - { path: ^/caps/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/caps/inscription, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/caps/*, roles: ROLE_USER }
Ma page de routing:
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 symfony_capsule_capsule: resource: "@SymfonyCapsuleCapsuleBundle/Resources/config/routing.yml" prefix: /caps tuto_animaux: resource: "@TutoAnimauxBundle/Resources/config/routing.yml" prefix: / hello: resource: "@HelloBundle/Resources/config/routing.yml" prefix: / login: pattern: /caps/login defaults: { _controller: SymfonyCapsuleCapsuleBundle:Default:login } inscription: pattern: /caps/inscription defaults: { _controller: SymfonyCapsuleCapsuleBundle:Default:inscription } login_check: pattern: /caps/login_check logout: pattern: /caps/logout # Internal routing configuration to handle ESI # ****** WARNING ****** # This route should be enabled with caution as it can open a security vulnerability # see http://symfony.com/blog/security-release-symfony-2-0-20-and-2-1-5-released for more information # ****** WARNING ****** #_internal: # resource: "@FrameworkBundle/Resources/config/routing/internal.xml" # prefix: /_internal
Voici une classe que j'ai crée grâce a ce tutoriel: http://hazamor.over-blog.com/article...-91974825.html
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 <?php namespace SymfonyCapsule\CapsuleBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\EntityRepository; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; class AdherentRepository extends EntityRepository implements UserProviderInterface { public function loadUserByUsername($username) { $adherent = $this->getEntityManager()->getRepository('SymfonyCapsuleCapsuleBundle:Adherent') ->findOneBy(array( 'pseudoAdherent' => $username )); return $adherent; } function refreshUser(UserInterface $user) { return $this->loadUserByUsername($user->getUsername()); } function supportsClass($class){ return true; } }
Partager