Implemented basic login process

This commit is contained in:
Kevin Frantz 2018-09-06 18:57:23 +02:00
parent 0148315961
commit 26c8da8b69
2 changed files with 18 additions and 4 deletions

View File

@ -9,6 +9,7 @@ use App\Entity\User;
use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
/** /**
* *
@ -31,14 +32,26 @@ class UserController extends AbstractController implements UserControllerInterfa
* *
* @Route("/user/register", name="user_register") * @Route("/user/register", name="user_register")
*/ */
public function register(): Response public function register(Request $request): Response
{ {
$user = new User(); $user = new User();
$form = $this->createFormBuilder($user) $form = $this->createFormBuilder($user)
->add('username', TextType::class) ->add('username', TextType::class)
->add('password', PasswordType::class) ->add('password', PasswordType::class)
->add('save', SubmitType::class,['label' => 'register']) ->add('save', SubmitType::class, [
'label' => 'register'
])
->getForm(); ->getForm();
return $this->render("user/register.html.twig",['form'=>$form->createView()]); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$task = $form->getData();
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($task);
$entityManager->flush();
}
return $this->render("user/register.html.twig", [
'form' => $form->createView()
]);
} }
} }

View File

@ -3,6 +3,7 @@ namespace App\Controller;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Request;
/** /**
* *
@ -13,5 +14,5 @@ interface UserControllerInterface
{ {
public function logout():Response; public function logout():Response;
public function register():Response; public function register(Request $request):Response;
} }