Completed
Pull Request — master (#2)
by Kate
15:18
created

SecurityController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 49
ccs 0
cts 32
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loginAction() 0 9 1
A registerAction() 0 20 3
A loginCheckAction() 0 4 1
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
    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
            $user->setEnabled(true);
39
            $em = $this->getDoctrine()->getManager();
40
            $em->persist($user);
41
            $em->flush();
42
            return $this->redirectToRoute('security_login_form');
43
        }
44
        return $this->render(
45
            'AppBundle:security:register.html.twig',
46
            array('form' => $form->createView())
47
        );
48
    }
49
50
    /**
51
     * @Route("/login_check", name="security_login_check")
52
     */
53
    public function loginCheckAction()
54
    {
55
        throw new \Exception('This should never be reached!');
56
    }
57
58
59
}
60