Skip to main content
spelling
Source Link
Jason Aller
  • 3.7k
  • 28
  • 43
  • 40

AuthenticationSuccessHandler, redirect after login and refererreferrer

I've just added with this forum's help an AuthenticationSuccessHandler wichwhich implements on my site a redirection when the user login via fosuserbundle or fosfacebookbundle. The redirection changes when the user has the profile completed or not, and if it has it completed, iI want himthem to be redirected where he wasthey were previously, this is why iI am using the refererreferrer variable.

my security.yml note that iI have the use_refereruse_referrer declared in both fos_facebook and form_login:

When iI login and i dontI don't have my profile completed, iI am getting redirected succesfullysuccessfully but when it is completed and refererreferrer is not null iI am having 500 erroserrors:

When iI login with facebook iFacebook I get an 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/facebook/login_check"

And when iI login with the form, iI get a 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/user/login_check"

Any ideas, iI am getting crazy. I thing its because the referalreferral has stored user/login and when it go to login_check goes to user/login again...

Thank you in advance!!!

AuthenticationSuccessHandler, redirect after login and referer

I've just added with this forum's help an AuthenticationSuccessHandler wich implements on my site a redirection when the user login via fosuserbundle or fosfacebookbundle. The redirection changes when the user has the profile completed or not, and if it has it completed, i want him to be redirected where he was previously, this is why i am using the referer variable.

my security.yml note that i have the use_referer declared in both fos_facebook and form_login:

When i login and i dont have my profile completed, i am getting redirected succesfully but when it is completed and referer is not null i am having 500 erros:

When i login with facebook i get an 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/facebook/login_check"

And when i login with the form, i get a 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/user/login_check"

Any ideas, i am getting crazy. I thing its because the referal has stored user/login and when it go to login_check goes to user/login again...

Thank you in advance!!!

AuthenticationSuccessHandler, redirect after login and referrer

I've just added with this forum's help an AuthenticationSuccessHandler which implements on my site a redirection when the user login via fosuserbundle or fosfacebookbundle. The redirection changes when the user has the profile completed or not, and if it has it completed, I want them to be redirected where they were previously, this is why I am using the referrer variable.

my security.yml note that I have the use_referrer declared in both fos_facebook and form_login:

When I login and I don't have my profile completed, I am getting redirected successfully but when it is completed and referrer is not null I am having 500 errors:

When I login with Facebook I get an 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/facebook/login_check"

And when I login with the form, I get a 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/user/login_check"

Any ideas, I am getting crazy. I thing its because the referral has stored user/login and when it go to login_check goes to user/login again.

Source Link
walolinux
  • 551
  • 1
  • 7
  • 20

AuthenticationSuccessHandler, redirect after login and referer

I've just added with this forum's help an AuthenticationSuccessHandler wich implements on my site a redirection when the user login via fosuserbundle or fosfacebookbundle. The redirection changes when the user has the profile completed or not, and if it has it completed, i want him to be redirected where he was previously, this is why i am using the referer variable.

 namespace Me\MyBundle\Handler; use Symfony\Component\Security\Http\HttpUtils; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler { protected $router; public function __construct( HttpUtils $httpUtils, array $options, $router) { $this->router = $router; parent::__construct( $httpUtils, $options ); } public function onAuthenticationSuccess( Request $request, TokenInterface $token ) { $user = $token->getUser(); if($user->getProfileComplete()!=1){ //redirects to profile editing $url = 'fos_user_profile_edit'; }else{ $referer = $request->headers->get('referer'); if($referer == NULL){ //redirects to custom url if there is not any referer $url = 'My_customurl'; }else{ //redirects to the referer $url = $referer; } } return new RedirectResponse($this->router->generate($url)); } } 

my security.yml note that i have the use_referer declared in both fos_facebook and form_login:

 firewalls: main: pattern: ^/ fos_facebook: app_url: "http://apps.facebook.com/app" server_url: "http://www.app.com" login_path: /user/login check_path: /facebook/login_check provider: fos_facebook_provider success_handler: my_auth_success_handler use_referer: true form_login: provider: fos_userbundle csrf_provider: form.csrf_provider login_path: /user/login check_path: /user/login_check use_forward: false success_handler: my_auth_success_handler use_referer: true failure_path: null logout: path: /user/logout anonymous: ~ remember_me: key: mySuperKey lifetime: 4147200 path: / domain: ~ 

When i login and i dont have my profile completed, i am getting redirected succesfully but when it is completed and referer is not null i am having 500 erros:

When i login with facebook i get an 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/facebook/login_check"

And when i login with the form, i get a 500 error: "Unable to generate a URL for the named route "http://app.com/app_dev.php/user/login" as such route does not exist." and the url in firefox is this: "http://app.com/app_dev.php/user/login_check"

Any ideas, i am getting crazy. I thing its because the referal has stored user/login and when it go to login_check goes to user/login again...

Thank you in advance!!!