|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Staff\User2; |
|
6
|
|
|
use App\Form\Type\RegistrationType; |
|
7
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
13
|
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; |
|
14
|
|
|
|
|
15
|
|
|
class SecurityController extends AbstractController |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/subscribtion", name="security_registration") |
|
19
|
|
|
*/ |
|
20
|
|
|
public function registration(Request $request, ObjectManager $manager, UserPasswordEncoderInterface $encoder) |
|
21
|
|
|
{ |
|
22
|
|
|
$user = new User2(); |
|
23
|
|
|
$form = $this->createForm(RegistrationType::class, $user, ['roles' => $this->getExistingRoles(),]); |
|
24
|
|
|
|
|
25
|
|
|
$form->handleRequest($request); |
|
26
|
|
|
|
|
27
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
28
|
|
|
$hash = $encoder->encodePassword($user, $user->getPassword()); |
|
29
|
|
|
|
|
30
|
|
|
$user->setPassword($hash); |
|
31
|
|
|
$user->setIsActive(true); |
|
32
|
|
|
|
|
33
|
|
|
$manager->persist($user); |
|
34
|
|
|
$manager->flush(); |
|
35
|
|
|
|
|
36
|
|
|
return $this->redirectToRoute('securityLogin'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $this->render('security/registration.html.twig', [ |
|
40
|
|
|
'form' => $form->createView() |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Login |
|
46
|
|
|
* |
|
47
|
|
|
* @Route("/connexion", name="securityLogin") |
|
48
|
|
|
*/ |
|
49
|
|
|
public function login() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->render('security/login.html.twig'); |
|
52
|
|
|
} |
|
53
|
|
|
/** |
|
54
|
|
|
* @Route("/deconnexion", name="securityLogout") |
|
55
|
|
|
*/ |
|
56
|
|
|
public function logout() |
|
57
|
|
|
{ |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the existing roles |
|
62
|
|
|
* |
|
63
|
|
|
* @return array Array of roles |
|
64
|
|
|
*/ |
|
65
|
|
|
private function getExistingRoles() |
|
66
|
|
|
{ |
|
67
|
|
|
$roleHierarchy = $this->getParameter('security.role_hierarchy.roles'); |
|
68
|
|
|
$roles = array_keys($roleHierarchy); |
|
69
|
|
|
$theRoles = array(); |
|
70
|
|
|
|
|
71
|
|
|
foreach ($roles as $role) { |
|
72
|
|
|
$theRoles[$role] = $role; |
|
73
|
|
|
} |
|
74
|
|
|
return $theRoles; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|