[CONTROLLER][Security] Override the `_next` form field in Security->register to redirect to login page
This commit is contained in:
parent
390c532456
commit
18864ca9fa
|
@ -11,6 +11,7 @@ use App\Core\Event;
|
||||||
use App\Core\Form;
|
use App\Core\Form;
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use App\Core\Log;
|
use App\Core\Log;
|
||||||
|
use App\Core\Router\Router;
|
||||||
use App\Entity\Actor;
|
use App\Entity\Actor;
|
||||||
use App\Entity\Feed;
|
use App\Entity\Feed;
|
||||||
use App\Entity\LocalUser;
|
use App\Entity\LocalUser;
|
||||||
|
@ -33,6 +34,7 @@ use Component\Subscription\Entity\ActorSubscription;
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||||
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;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
@ -96,7 +98,8 @@ class Security extends Controller
|
||||||
// \App\Core\Security $authenticator,
|
// \App\Core\Security $authenticator,
|
||||||
// UserAuthenticatorInterface $user_authenticator,
|
// UserAuthenticatorInterface $user_authenticator,
|
||||||
): array|Response {
|
): array|Response {
|
||||||
$form = Form::create([
|
$form = Form::create(
|
||||||
|
[
|
||||||
['nickname', TextType::class, [
|
['nickname', TextType::class, [
|
||||||
'label' => _m('Nickname'),
|
'label' => _m('Nickname'),
|
||||||
'help' => _m('Your desired nickname (e.g., j0hnD03)'),
|
'help' => _m('Your desired nickname (e.g., j0hnD03)'),
|
||||||
|
@ -121,8 +124,11 @@ class Security extends Controller
|
||||||
'attr' => ['autocomplete' => 'email'],
|
'attr' => ['autocomplete' => 'email'],
|
||||||
]],
|
]],
|
||||||
FormFields::repeated_password(['attr' => ['autocomplete' => 'new-password']]),
|
FormFields::repeated_password(['attr' => ['autocomplete' => 'new-password']]),
|
||||||
['register', SubmitType::class, ['label' => _m('Register')]],
|
['register', SubmitType::class, ['label' => _m('Register')]]
|
||||||
], form_options: ['block_prefix' => 'register']);
|
],
|
||||||
|
extra_data: ['_next' => Router::url('security_login')],
|
||||||
|
form_options: ['block_prefix' => 'register']
|
||||||
|
);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
@ -205,6 +211,7 @@ class Security extends Controller
|
||||||
$user->setIsEmailVerified(true);
|
$user->setIsEmailVerified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Form::forceRedirect($form, $request);
|
||||||
// return $user_authenticator->authenticateUser($user, $authenticator, $request);
|
// return $user_authenticator->authenticateUser($user, $authenticator, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ abstract class Form
|
||||||
): SymfFormInterface {
|
): SymfFormInterface {
|
||||||
$name = $form[array_key_last($form)][0];
|
$name = $form[array_key_last($form)][0];
|
||||||
$r = Common::getRequest();
|
$r = Common::getRequest();
|
||||||
|
|
||||||
$form[] = ['_next', HiddenType::class, ['data' => $r->get('next') ?? $r->get('_next') ?? $r->getRequestUri()]];
|
$form[] = ['_next', HiddenType::class, ['data' => $r->get('next') ?? $r->get('_next') ?? $r->getRequestUri()]];
|
||||||
|
|
||||||
$fb = self::$form_factory->createNamedBuilder($name, $type, data: null, options: array_merge($form_options, ['translation_domain' => false]));
|
$fb = self::$form_factory->createNamedBuilder($name, $type, data: null, options: array_merge($form_options, ['translation_domain' => false]));
|
||||||
|
|
Loading…
Reference in New Issue