Passed
Push — master ( 582587...3b42e9 )
by Anthony
04:10 queued 11s
created

RegistrationController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B registerAction() 0 28 3
1
<?php
2
3
namespace Ribs\RibsAdminBundle\Controller;
4
5
use Ribs\RibsAdminBundle\Form\Registration;
6
use Ribs\RibsAdminBundle\Entity\Account;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\Routing\Annotation\Route;
10
11
class RegistrationController extends Controller
12
{
13
	/**
14
	 * @Route("/register/", name="ribsadmin_register")
15
	 */
16
	public function registerAction(Request $request)
17
	{
18
		// 1) build the form
19
		$passwordEncoder = $this->get("security.password_encoder");
20
		$user = new Account();
21
		$form = $this->createForm(Registration::class, $user);
22
		
23
		// 2) handle the submit (will only happen on POST)
24
		$form->handleRequest($request);
25
		if ($form->isSubmitted() && $form->isValid()) {
26
			//$password = $passwordEncoder->encodePassword($user, "ap@2010");
27
			
28
			// 3) Encode the password (you could also do this via Doctrine listener)
29
			$password = $passwordEncoder->encodePassword($user, $user->getPassword());
30
			$user->setPassword($password);
31
			
32
			// 4) save the User!
33
			$em = $this->getDoctrine()->getManager();
34
			$em->persist($user);
35
			$em->flush();
36
			
37
			// ... do any other work - like sending them an email, etc
38
			// maybe set a "flash" success message for the user
39
			
40
			return $this->redirectToRoute('replace_with_some_route');
41
		}
42
		
43
		return $this->render("@RibsAdmin/registration/registration.html", ['form' => $form->createView()]);
44
	}
45
}