|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
7
|
|
|
use AppBundle\Form\UserType; |
|
8
|
|
|
use AppBundle\Entity\User; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
|
|
11
|
|
|
class SecurityController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @Route("/login", name="security_login_form") |
|
15
|
|
|
*/ |
|
16
|
|
|
public function loginAction() |
|
17
|
|
|
{ |
|
18
|
|
|
$helper = $this->get('security.authentication_utils'); |
|
19
|
|
|
|
|
20
|
|
|
return $this->render('AppBundle:security:login.html.twig', array( |
|
21
|
|
|
'last_username' => $helper->getLastUsername(), |
|
22
|
|
|
'error' => $helper->getLastAuthenticationError(), |
|
23
|
|
|
)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @Route("/register", name="user_registration") |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
public function registerAction(Request $request) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$user = new User(); |
|
32
|
|
|
$form = $this->createForm(UserType::class, $user); |
|
33
|
|
|
$form->handleRequest($request); |
|
34
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
35
|
|
|
$password = $this->get('security.password_encoder') |
|
36
|
|
|
->encodePassword($user, $user->getPlainPassword()); |
|
37
|
|
|
$user->setPassword($password); |
|
38
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
39
|
|
|
$em->persist($user); |
|
40
|
|
|
$em->flush(); |
|
41
|
|
|
return $this->redirectToRoute('security_login_form'); |
|
42
|
|
|
} |
|
43
|
|
|
return $this->render( |
|
44
|
|
|
'AppBundle:security:register.html.twig', |
|
45
|
|
|
array('form' => $form->createView()) |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @Route("/login_check", name="security_login_check") |
|
51
|
|
|
*/ |
|
52
|
|
|
public function loginCheckAction() |
|
53
|
|
|
{ |
|
54
|
|
|
throw new \Exception('This should never be reached!'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.