How to disable redirection after login_check in Symfony 2
Create an authentication handler:
namespace YourVendor\UserBundle\Handler;
// "use" statements here
class AuthenticationHandler
implements AuthenticationSuccessHandlerInterface,
AuthenticationFailureHandlerInterface
{
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
if ($request->isXmlHttpRequest()) {
$result = array('success' => true);
return new Response(json_encode($result));
} else {
// Handle non XmlHttp request here
}
}
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if ($request->isXmlHttpRequest()) {
$result = array('success' => false);
return new Response(json_encode($result));
} else {
// Handle non XmlHttp request here
}
}
}
Register the handler as a service:
services:
authentication_handler:
class: YourVendor\UserBundle\Handler\AuthenticationHandler
Register the service in the firewall:
firewalls:
main:
form_login:
success_handler: authentication_handler
failure_handler: authentication_handler
This is a rough example to give you the general idea — you'll need to figure out the details by yourself. If you're stuck and need further clarifications, put your questions in the comments and I'll try to elaborate the example.
Symfony2 FOS weird redirect after login
Try putting this in firewall:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
...
This should stop redirecting to url of type 'wdt'.
How to make differents redirections after login Symfony
The most safe implementation is to register to the InteractiveLoginEvent
, by which you can do something after the user logged in successfully.
app.login_listener:
class: AppBundle\EventListener\LoginListener
arguments:
- @session
tags:
- { name: kernel.event_listener, event: security.interactive_login, method: onLoginSuccess }
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
You can check the session during onLoginSuccess
for your form, and return the proper redirect response in onKernelResponse
.
Symfony2. Forwarding to login_check in isn't interceipted
Trying to perform a redirect with POST is not a good idea. Here's why:
https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect
The best way is to create token & emit login event:
How to programmatically login/authenticate a user?
Related Topics
Issue with Laravel Rules & Regex (Or) Operator
Understanding Pdo MySQL Transactions
Order Multidimensional Array Recursively at Each Level in PHP
Array_Key_Exists Is Not Working
How to Store and Retrieve Image Contents from the Database Using Laravel
Get Value from JSON Array in PHP
How to Pass Data Between Pages in PHP
Get Numbers from String with PHP
PHP Simplexml: Insert Node at Certain Position
Php: Using Domdocument Whenever I Try to Write Utf-8 It Writes the Hexadecimal Notation of It
Differencebetween the PHP Open Tags "<=" and "<Php"/"<"
Get All Instances of a Class in PHP
Why Does PHP Echo'D Text Lose Its Formatting
How to Pass Jquery Variables to PHP Variable
Pre-Incrementation VS. Post-Incrementation