#20 add username form

This commit is contained in:
Jonas 2024-06-27 17:43:14 +02:00
parent b479fbf5ed
commit 9d81464fd8
Signed by: lubiana
SSH key fingerprint: SHA256:gkqM8DUX4Blf6P52fycW8ISTd+4eAHH+Uzu9iyc8hAM
2 changed files with 41 additions and 1 deletions

View file

@ -2,16 +2,32 @@
namespace App\Controller; namespace App\Controller;
use App\Form\UserNameFormType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
final class HomeController final class HomeController extends AbstractController
{ {
public const string DEFAULT_USERNAME = 'nobody';
#[Route('/', name: 'home')] #[Route('/', name: 'home')]
public function home(UrlGeneratorInterface $router): Response public function home(UrlGeneratorInterface $router): Response
{ {
return new RedirectResponse($router->generate('app_food_order_index')); return new RedirectResponse($router->generate('app_food_order_index'));
} }
public function usernameForm(Request $request): Response
{
$username = $request->cookies->get('username', self::DEFAULT_USERNAME);
$form = $this->createForm(UsernameFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$username = $form->getData()['username'] ?? self::DEFAULT_USERNAME;
if ($username === '') {}
}
}
} }

View file

@ -0,0 +1,24 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserNameFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}