This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » plugins » User management plugins » After SignIn, Redirect to requested page (route), and not referrer
After SignIn, Redirect to requested page (route), and not referrer [message #99950] Thu, 27 May 2010 17:25
prasadgupte
Messages: 12
Registered: April 2010
Location: India
Junior Member
I want to be able to take the user to the requested page after login, but this does not happen with sfGuard.
** My Register action requires SignIn Wink **

On the listing page [http://cim/frontend_dev.php/]
-> user clicks the 'Register' link [@register = register/index]
-> user is taken to 'Signin' page provided by sfGuard
-> after sign-in, user is taken back to the Listing page (instead of Register)
This is quite annoying! But logical, because the referrer is the listing page.

How can I change logic to make @register the referrer? Pl help. thanks

    public function executeSignin($request)
      {
        $user = $this->getUser();
        $this->logMessage('Signin>>> form - isAuth() '.$user->isAuthenticated(), 'info');
    
        if ($user->isAuthenticated())
        {
    		$this->getUser()->setAttribute('tenant', $this->getUser()->getGuardUser()->sfuser->Tenant->getID());
    		return $this->redirect($user->getReferer($request->getReferer()));
        }
    
        $class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin'); 
        $this->form = new $class();
        $referer = $user->getReferer($request->getReferer());
        $this->logMessage('Signin>>> referer: '.$referer, 'info');
        $this->logMessage('Signin>>> referer: '.$request->getReferer(), 'info');
    
        if ($request->isMethod('post'))
        {
          $this->form->bind($request->getParameter('signin'));
          if ($this->form->isValid())
          {
            $values = $this->form->getValues(); 
            $this->getUser()->signin($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);
            $this->getUser()->setAttribute('tenant', $this->getUser()->getGuardUser()->sfuser->Tenant->getID());
            
            $this->logMessage('Signin>>> sfUrl | @homepage: '.sfConfig::get('app_sf_guard_plugin_success_signin_url','@homepage'), 'info');
            return $this->redirect("" != $referer ? $referer : sfConfig::get('app_sf_guard_plugin_success_signin_url','@homepage'));
          }
        }
        else
        {
          if ($request->isXmlHttpRequest())
          {
            $this->getResponse()->setHeaderOnly(true);
            $this->getResponse()->setStatusCode(401);
    
            return sfView::NONE;
          }
    
          // if we have been forwarded, then the referer is the current URL
          // if not, this is the referer of the current request
          $user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());
    
          $this->logMessage('Signin>>> oldy: '.$request->getUri(), 'info');
          $this->logMessage('Signin>>> oldy: '.$request->getReferer(), 'info');
    
          $module = sfConfig::get('sf_login_module');
          if ($this->getModuleName() != $module)
          {
            return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
          }
    
          $this->getResponse()->setStatusCode(401);
        }
      }


Trace:
    May 27 10:10:14 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signin" (/login)
    May 27 10:10:14 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signout" (/logout)
    May 27 10:10:14 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_password" (/request_password)
    May 27 10:10:14 symfony [info] {sfPatternRouting} Match route "register" (/register) for /register with parameters array (  'module' => 'register',  'action' => 'index',)
    May 27 10:10:14 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
    May 27 10:10:14 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
    May 27 10:10:14 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
    May 27 10:10:14 symfony [info] {registerActions} Call "registerActions->executeIndex()"
    May 27 10:10:14 symfony [info] {sfFrontWebController} Redirect to "http://cim/frontend_dev.php/login"
    May 27 10:10:14 symfony [info] {sfWebResponse} Send status "HTTP/1.1 302 Found"
    May 27 10:10:14 symfony [info] {sfWebResponse} Send header "Location: http://cim/frontend_dev.php/login"
    May 27 10:10:14 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
    May 27 10:10:14 symfony [info] {sfWebDebugLogger} Configuration 13.39 ms (9)
    May 27 10:10:14 symfony [info] {sfWebDebugLogger} Factories 50.02 ms (1)
    May 27 10:10:14 symfony [info] {sfWebDebugLogger} Action "register/index" 1.94 ms (1)
    May 27 10:10:14 symfony [info] {sfWebResponse} Send content (104 o)
    May 27 10:10:16 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signin" (/login)
    May 27 10:10:16 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signout" (/logout)
    May 27 10:10:16 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_password" (/request_password)
    May 27 10:10:16 symfony [info] {sfPatternRouting} Match route "sf_guard_signin" (/login) for /login with parameters array (  'module' => 'sfGuardAuth',  'action' => 'signin',)
    May 27 10:10:16 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
    May 27 10:10:16 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
    May 27 10:10:16 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
    May 27 10:10:16 symfony [info] {sfGuardAuthActions} Call "sfGuardAuthActions->executeSignin()"
    May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin>>> form - isAuth() 
    May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin>>> referer: http://cim/frontend_dev.php/
    May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin>>> referer: http://cim/frontend_dev.php/
    May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin>>> oldy: http://cim/frontend_dev.php/login
    May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin>>> oldy: http://cim/frontend_dev.php/
    May 27 10:10:16 symfony [info] {sfPHPView} Render "D:/projects/cim/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/signinSuccess.php"
    May 27 10:10:16 symfony [info] {sfPHPView} Decorate content with "D:\projects\cim\apps\frontend\templates/layout.php"
    May 27 10:10:16 symfony [info] {sfPHPView} Render "D:\projects\cim\apps\frontend\templates/layout.php"
    May 27 10:10:16 symfony [info] {main} Get slot "title"
    May 27 10:10:16 symfony [info] {sfWebResponse} Send status "HTTP/1.1 401 Unauthorized"
    May 27 10:10:16 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
    May 27 10:10:16 symfony [info] {sfWebDebugLogger} Configuration 16.06 ms (10)
    May 27 10:10:16 symfony [info] {sfWebDebugLogger} Factories 50.00 ms (1)
    May 27 10:10:16 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 14.53 ms (1)
    May 27 10:10:16 symfony [info] {sfWebDebugLogger} View "Success" for "sfGuardAuth/signin" 34.44 ms (1)
    May 27 10:10:16 symfony [info] {sfWebResponse} Send content (38057 o)
Previous Topic:[resolved] sfForkedDoctrineApply reset password
Next Topic:Unable to $form->save() and setPassword() in one action
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software