Passed
Push — main ( bfbca3...f1aa52 )
by Karl
08:21
created

RegistrationController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
eloc 15
c 2
b 0
f 1
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 26 2
1
<?php
2
3
namespace App\Controller\Kassabok;
4
5
use App\Entity\User;
6
use App\Form\RegistrationFormType;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
12
use Symfony\Component\Routing\Attribute\Route;
13
14
class RegistrationController extends AbstractController
15
{
16
    #[Route('proj/register', name: 'kassabok_register')]
17
    public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
18
    {
19
        $user = new User();
20
        $form = $this->createForm(RegistrationFormType::class, $user);
21
        $form->handleRequest($request);
22
23
        if ($form->isSubmitted()) { //&& $form->isValid()) {
24
            // encode the plain password
25
            $user->setPassword(
26
                $userPasswordHasher->hashPassword(
27
                    $user,
28
                    $form->get('plainPassword')->getData()
29
                )
30
            );
31
32
            $entityManager->persist($user);
33
            $entityManager->flush();
34
35
            // do anything else you need here, like send an email
36
37
            return $this->redirectToRoute('kassabok_start');
38
        }
39
40
        return $this->render('./kassabok/registration/register.html.twig', [
41
            'registrationForm' => $form,
42
        ]);
43
    }
44
}
45