wip-feat: reduces env vars, adds getting-started page
This commit is contained in:
@@ -2,16 +2,31 @@
|
||||
|
||||
namespace App\User\Framework\Controller\Web;
|
||||
|
||||
use App\User\Action\Command\RegisterUserCommand;
|
||||
use App\User\Action\Handler\RegisterUserHandler;
|
||||
use App\User\Framework\Entity\User;
|
||||
use App\User\Framework\Form\RegistrationFormType;
|
||||
use App\User\Framework\Repository\UserRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class LoginController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/login', name: 'app_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
public function __construct(private readonly RegisterUserHandler $registerUserHandler)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route(path: '/login', name: 'app_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils, UserRepository $userRepository): Response
|
||||
{
|
||||
if ((new ArrayCollection($userRepository->findAll()))->count() === 0) {
|
||||
return $this->redirectToRoute('app_getting_started');
|
||||
}
|
||||
|
||||
// get the login error if there is one
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
|
||||
@@ -29,4 +44,26 @@ class LoginController extends AbstractController
|
||||
{
|
||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
||||
}
|
||||
|
||||
#[Route(path: '/getting-started', name: 'app_getting_started')]
|
||||
public function gettingStarted(Request $request): Response
|
||||
{
|
||||
$form = $this->createForm(RegistrationFormType::class, new User());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->registerUserHandler->handle(new RegisterUserCommand(
|
||||
name: $form->get('name')->getData(),
|
||||
email: $form->get('email')->getData(),
|
||||
username: $form->get('username')->getData(),
|
||||
password: $form->get('plainPassword')->getData(),
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('app_index');
|
||||
}
|
||||
|
||||
return $this->render('user/getting-started.html.twig', [
|
||||
'registrationForm' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user