Clean up registerForm
This commit is contained in:
parent
3b0c9ff4ca
commit
f271d2d6ac
@ -13,9 +13,9 @@ class LoginController extends AbstractController
|
|||||||
#[Route('/login', name: 'login')]
|
#[Route('/login', name: 'login')]
|
||||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||||
{
|
{
|
||||||
// if ($this->getUser()) {
|
if ($this->getUser()) {
|
||||||
// return $this->redirectToRoute('target_path');
|
return $this->redirectToRoute('home');
|
||||||
// }
|
}
|
||||||
|
|
||||||
// get the login error if there is one
|
// get the login error if there is one
|
||||||
$error = $authenticationUtils->getLastAuthenticationError();
|
$error = $authenticationUtils->getLastAuthenticationError();
|
||||||
|
@ -13,8 +13,12 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||||||
|
|
||||||
class RegistrationController extends AbstractController
|
class RegistrationController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/register', name: 'app_register')]
|
#[Route('/register', name: 'register')]
|
||||||
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
|
public function register(
|
||||||
|
Request $request,
|
||||||
|
UserPasswordHasherInterface $userPasswordHasher,
|
||||||
|
EntityManagerInterface $entityManager
|
||||||
|
): Response
|
||||||
{
|
{
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$form = $this->createForm(RegistrationFormType::class, $user);
|
$form = $this->createForm(RegistrationFormType::class, $user);
|
||||||
@ -23,7 +27,7 @@ class RegistrationController extends AbstractController
|
|||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
// encode the plain password
|
// encode the plain password
|
||||||
$user->setPassword(
|
$user->setPassword(
|
||||||
$userPasswordHasher->hashPassword(
|
$userPasswordHasher->hashPassword(
|
||||||
$user,
|
$user,
|
||||||
$form->get('plainPassword')->getData()
|
$form->get('plainPassword')->getData()
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@ use App\Entity\User;
|
|||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
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\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
@ -18,14 +19,6 @@ class RegistrationFormType extends AbstractType
|
|||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('username')
|
->add('username')
|
||||||
->add('agreeTerms', CheckboxType::class, [
|
|
||||||
'mapped' => false,
|
|
||||||
'constraints' => [
|
|
||||||
new IsTrue([
|
|
||||||
'message' => 'You should agree to our terms.',
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
])
|
|
||||||
->add('plainPassword', PasswordType::class, [
|
->add('plainPassword', PasswordType::class, [
|
||||||
// instead of being set onto the object directly,
|
// instead of being set onto the object directly,
|
||||||
// this is read and encoded in the controller
|
// this is read and encoded in the controller
|
||||||
@ -43,6 +36,15 @@ class RegistrationFormType extends AbstractType
|
|||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
|
->add('agreeTerms', CheckboxType::class, [
|
||||||
|
'mapped' => false,
|
||||||
|
'constraints' => [
|
||||||
|
new IsTrue([
|
||||||
|
'message' => 'You should agree to our terms.',
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->add('register', SubmitType::class)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,5 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Register</h1>
|
<h1>Register</h1>
|
||||||
|
|
||||||
{{ form_start(registrationForm) }}
|
{{ form(registrationForm) }}
|
||||||
{{ form_row(registrationForm.username) }}
|
|
||||||
{{ form_row(registrationForm.plainPassword, {
|
|
||||||
label: 'Password'
|
|
||||||
}) }}
|
|
||||||
{{ form_row(registrationForm.agreeTerms) }}
|
|
||||||
|
|
||||||
<button type="submit" class="btn">Register</button>
|
|
||||||
{{ form_end(registrationForm) }}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user