fix: logs user in after registration
This commit is contained in:
10
src/Twig/Components/TextInput.php
Normal file
10
src/Twig/Components/TextInput.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Twig\Components;
|
||||||
|
|
||||||
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||||
|
|
||||||
|
#[AsTwigComponent]
|
||||||
|
final class TextInput
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -8,9 +8,9 @@ use OneToMany\RichBundle\Contract\CommandInterface;
|
|||||||
class RegisterUserCommand implements CommandInterface
|
class RegisterUserCommand implements CommandInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $name,
|
public ?string $name = null,
|
||||||
public string $email,
|
public ?string $email = null,
|
||||||
public string $username,
|
public ?string $username = null,
|
||||||
public string $password,
|
public ?string $password = null,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
@@ -2,24 +2,17 @@
|
|||||||
|
|
||||||
namespace App\User\Framework\Controller\Web;
|
namespace App\User\Framework\Controller\Web;
|
||||||
|
|
||||||
use App\User\Action\Command\RegisterUserCommand;
|
|
||||||
use App\User\Action\Handler\RegisterUserHandler;
|
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 App\User\Framework\Repository\UserRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
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\Security\Http\Authentication\AuthenticationUtils;
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||||
|
|
||||||
class LoginController extends AbstractController
|
class LoginController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(private readonly RegisterUserHandler $registerUserHandler)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route(path: '/login', name: 'app_login')]
|
#[Route(path: '/login', name: 'app_login')]
|
||||||
public function login(AuthenticationUtils $authenticationUtils, UserRepository $userRepository): Response
|
public function login(AuthenticationUtils $authenticationUtils, UserRepository $userRepository): Response
|
||||||
{
|
{
|
||||||
@@ -44,26 +37,4 @@ class LoginController extends AbstractController
|
|||||||
{
|
{
|
||||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
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,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,11 @@ namespace App\User\Framework\Controller\Web;
|
|||||||
use App\User\Action\Command\RegisterUserCommand;
|
use App\User\Action\Command\RegisterUserCommand;
|
||||||
use App\User\Action\Handler\RegisterUserHandler;
|
use App\User\Action\Handler\RegisterUserHandler;
|
||||||
use App\User\Framework\Entity\User;
|
use App\User\Framework\Entity\User;
|
||||||
use App\User\Framework\Entity\UserPreference;
|
|
||||||
use App\User\Framework\Form\RegistrationFormType;
|
use App\User\Framework\Form\RegistrationFormType;
|
||||||
use App\User\Framework\Repository\PreferencesRepository;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
class RegistrationController extends AbstractController
|
class RegistrationController extends AbstractController
|
||||||
@@ -24,18 +21,21 @@ class RegistrationController extends AbstractController
|
|||||||
#[Route('/register', name: 'app_register')]
|
#[Route('/register', name: 'app_register')]
|
||||||
public function register(
|
public function register(
|
||||||
Request $request,
|
Request $request,
|
||||||
|
Security $security,
|
||||||
): Response {
|
): Response {
|
||||||
$form = $this->createForm(RegistrationFormType::class, new User());
|
$form = $this->createForm(RegistrationFormType::class, new User());
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$this->registerUserHandler->handle(new RegisterUserCommand(
|
$user = $this->registerUserHandler->handle(new RegisterUserCommand(
|
||||||
name: $form->get('name')->getData(),
|
name: $form->get('name')->getData(),
|
||||||
email: $form->get('email')->getData(),
|
email: $form->get('email')->getData(),
|
||||||
username: $form->get('username')->getData(),
|
username: $form->get('username')->getData(),
|
||||||
password: $form->get('plainPassword')->getData(),
|
password: $form->get('plainPassword')->getData(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$security->login($user->user);
|
||||||
|
|
||||||
return $this->redirectToRoute('app_index');
|
return $this->redirectToRoute('app_index');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,4 +43,27 @@ class RegistrationController extends AbstractController
|
|||||||
'registrationForm' => $form,
|
'registrationForm' => $form,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route(path: '/getting-started', name: 'app_getting_started')]
|
||||||
|
public function gettingStarted(Request $request, Security $security): Response
|
||||||
|
{
|
||||||
|
$form = $this->createForm(RegistrationFormType::class, new User());
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$user = $this->registerUserHandler->handle(new RegisterUserCommand(
|
||||||
|
name: $form->get('name')->getData(),
|
||||||
|
email: $form->get('email')->getData(),
|
||||||
|
password: $form->get('plainPassword')->getData(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$security->login($user->user);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_index');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('user/getting-started.html.twig', [
|
||||||
|
'registrationForm' => $form,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class RegistrationFormType extends AbstractType
|
|||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('email')
|
->add('email')
|
||||||
->add('username')
|
|
||||||
->add('name')
|
->add('name')
|
||||||
->add('plainPassword', PasswordType::class, [
|
->add('plainPassword', PasswordType::class, [
|
||||||
// instead of being set onto the object directly,
|
// instead of being set onto the object directly,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
{% block importmap %}{{ importmap('app') }}{% endblock %}
|
{% block importmap %}{{ importmap('app') }}{% endblock %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-cyan-950 flex flex-col">
|
<body class="bg-cyan-950 flex flex-col h-full">
|
||||||
<h1 class="px-4 py-4 text-3xl font-extrabold text-orange-500">Torsearch</h1>
|
<h1 class="px-4 py-4 text-3xl font-extrabold text-orange-500">Torsearch</h1>
|
||||||
<div class="flex flex-col justify-center items-center">
|
<div class="flex flex-col justify-center items-center">
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html class="bg-gradient-to-r from-neutral-700 to-stone-600">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{% block title %}Welcome!{% endblock %}</title>
|
<title>{% block title %}Welcome!{% endblock %}</title>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
{% block importmap %}{{ importmap('app') }}{% endblock %}
|
{% block importmap %}{{ importmap('app') }}{% endblock %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body class="flex flex-col">
|
<body class="flex flex-col bg-stone-700">
|
||||||
<div class="grid grid-cols-6">
|
<div class="grid grid-cols-6">
|
||||||
<div class="col-span-1 h-screen">
|
<div class="col-span-1 h-screen">
|
||||||
<twig:NavBar />
|
<twig:NavBar />
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
{{ form_start(registrationForm) }}
|
{{ form_start(registrationForm) }}
|
||||||
|
|
||||||
|
{### Start Name ###}
|
||||||
<label for="name" class="flex flex-col mb-2">
|
<label for="name" class="flex flex-col mb-2">
|
||||||
{{ field_label(registrationForm.name) }}
|
{{ field_label(registrationForm.name) }}
|
||||||
|
|
||||||
@@ -24,23 +25,9 @@
|
|||||||
value="{{ field_value(registrationForm.name) }}"
|
value="{{ field_value(registrationForm.name) }}"
|
||||||
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400" />
|
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400" />
|
||||||
</label>
|
</label>
|
||||||
|
{# ################### #}
|
||||||
|
|
||||||
<label for="username" class="flex flex-col mb-2">
|
{### Start Email ###}
|
||||||
{{ field_label(registrationForm.username) }}
|
|
||||||
|
|
||||||
{% if form_errors(registrationForm.username) %}
|
|
||||||
<span class="w-full p-1 text-[.775rem] font-bold border-2 border-red-600 text-black bg-red-500/70 rounded-md">
|
|
||||||
{{ form_errors(registrationForm.username) }}
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<input type="text"
|
|
||||||
name="{{ field_name(registrationForm.username) }}"
|
|
||||||
id="{{ field_name(registrationForm.username) }}"
|
|
||||||
value="{{ field_value(registrationForm.username) }}"
|
|
||||||
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400" />
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label for="email" class="flex flex-col mb-2">
|
<label for="email" class="flex flex-col mb-2">
|
||||||
{{ field_label(registrationForm.email) }}
|
{{ field_label(registrationForm.email) }}
|
||||||
|
|
||||||
@@ -56,22 +43,25 @@
|
|||||||
value="{{ field_value(registrationForm.email) }}"
|
value="{{ field_value(registrationForm.email) }}"
|
||||||
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400" />
|
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400" />
|
||||||
</label>
|
</label>
|
||||||
|
{# ################### #}
|
||||||
|
|
||||||
<label for="password" class="flex flex-col mb-2">
|
{### Start Password ###}
|
||||||
{{ field_label(registrationForm.plainPassword) }}
|
<label for="password" class="flex flex-col mb-2">
|
||||||
|
{{ field_label(registrationForm.plainPassword) }}
|
||||||
|
|
||||||
{% if form_errors(registrationForm.plainPassword) %}
|
{% if form_errors(registrationForm.plainPassword) %}
|
||||||
<span class="w-full p-1 text-[.775rem] font-bold border-2 border-red-600 text-black bg-red-500/70 rounded-md">
|
<span class="w-full p-1 text-[.775rem] font-bold border-2 border-red-600 text-black bg-red-500/70 rounded-md">
|
||||||
{{ form_errors(registrationForm.plainPassword) }}
|
{{ form_errors(registrationForm.plainPassword) }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<input type="password"
|
<input type="password"
|
||||||
name="{{ field_name(registrationForm.plainPassword) }}"
|
name="{{ field_name(registrationForm.plainPassword) }}"
|
||||||
id="{{ field_name(registrationForm.plainPassword) }}"
|
id="{{ field_name(registrationForm.plainPassword) }}"
|
||||||
value="{{ field_value(registrationForm.plainPassword) }}"
|
value="{{ field_value(registrationForm.plainPassword) }}"
|
||||||
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400 mb-3" />
|
class="bg-gray-50 text-gray-50 p-1 bg-transparent border-b-2 border-orange-400 mb-3" />
|
||||||
</label>
|
</label>
|
||||||
|
{# ################### #}
|
||||||
|
|
||||||
<button type="submit" class="bg-green-600/40 px-1.5 py-1 w-full rounded-md text-gray-50 backdrop-filter backdrop-blur-sm border-2 border-green-500 hover:bg-green-700/40">Register</button>
|
<button type="submit" class="bg-green-600/40 px-1.5 py-1 w-full rounded-md text-gray-50 backdrop-filter backdrop-blur-sm border-2 border-green-500 hover:bg-green-700/40">Register</button>
|
||||||
{{ form_end(registrationForm) }}
|
{{ form_end(registrationForm) }}
|
||||||
|
|||||||
Reference in New Issue
Block a user