Accepting the idea of ββ@Prynz, we can continue and create a "redirect to user page" as follows:
1) In your firewall, take care to remove the following lines:
# security.yml
How we will implement the exit from the system itself to avoid redirecting to the specified target
.
2) Add the @Prynz solution to your security.yml (or config.yml depending on your implementation)
oauth: resource_owners: google: "/login/check-google" facebook: "/login/check-facebook" twitter: "/login/check-twitter" sensio_connect: "/login/check-sensio-connect" login_path: /login failure_path: /login default_target_path: /welcome # THIS LINE CONTRIBUTES TO THE MAGIC oauth_user_provider: service: app.oauth_user_provider
3) In your routing, add a new controller (here LoginController
) before importing HWIO :
fuz_app_login: resource: "@FuzAppBundle/Controller/LoginController.php" type: annotation prefix: /
4) Create the appropriate controller:
<?php namespace Fuz\AppBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RedirectResponse; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; class LoginController { /** * @Route("/login", name="login") * @Method({"GET"}) */ public function loginAction(Request $request) { if ($this->getUser()) { // already-logged user accessed /login return $this->redirect($request->headers->get('referer')); } else { // redirect to the login page return $this->forward('HWIOAuthBundle:Connect:connect'); } } /** * @Route("/logout", name="logout") * @Method({"GET"}) */ public function logoutAction(Request $request) { // we do a manual logout just to redirect the user to where he comes from $this->container->get('security.context')->setToken(null); return $this->redirect($request->headers->get('referer')); } /** * @Route("/connect/{service}", name="connect") * @Method({"GET"}) */ public function connectAction(Request $request, $service) { // we overwrite this route to store user referer in the session $this->get('session')->set('referer', $request->headers->get('referer')); return $this->forward('HWIOAuthBundle:Connect:redirectToService', array('service' => $service)); } /** * @Route("/welcome", name="welcome") * @Method({"GET"}) */ public function welcomeAction() { // on login success, we're redirected to this route... // time to use the referer we previously stored. $referer = $this->get('session')->get('referer'); if (is_null($referer)) { return new RedirectResponse($this->generateUrl('home')); } return new RedirectResponse($referer); } }
5) relax.
source share