Completed
Pull Request — master (#2)
by Kate
03:29
created

SecurityController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loginAction() 0 9 1
A registerAction() 0 19 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
            $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