How to call a custom function in a sfGuard session in symfony

I am using sfGuard as an authentication plugin in my project. I want to invoke specific scripts on the client side and on the server side during a session timeout. How can I do this.

Please, help! Many thanks.

+3
source share
1 answer

Well, I read sfGuardSecurityUser and it extends the sfBasicSecurityUser class, because it handles user authentication, profile, credentials, etc. So, I found a function in sfBasicSecurityUser that determines if user sessions are assigned to the so-called isTimedOut, as well as setTimedOut.

- , , , , , . :

symfony_core_root_dir/lib/user/sfBasicSecurityUser.class.php

  public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
  {
    // initialize parent
    parent::initialize($dispatcher, $storage, $options);

    if (!array_key_exists('timeout', $this->options))
    {
      $this->options['timeout'] = 1800;
    }

    // force the max lifetime for session garbage collector to be greater than timeout
    if (ini_get('session.gc_maxlifetime') < $this->options['timeout'])
    {
      ini_set('session.gc_maxlifetime', $this->options['timeout']);
    }

    // read data from storage
    $this->authenticated = $storage->read(self::AUTH_NAMESPACE);
    $this->credentials   = $storage->read(self::CREDENTIAL_NAMESPACE);
    $this->lastRequest   = $storage->read(self::LAST_REQUEST_NAMESPACE);

    if (null === $this->authenticated)
    {
      $this->authenticated = false;
      $this->credentials   = array();
    }
    else
    {
      // Automatic logout logged in user if no request within timeout parameter seconds
      $timeout = $this->options['timeout'];
      if (false !== $timeout && null !== $this->lastRequest && time() - $this->lastRequest >= $timeout)
      {
        if ($this->options['logging'])
        {
          $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Automatic user logout due to timeout')));
        }

        $this->setTimedOut();
        $this->setAuthenticated(false);
      }
    }

    $this->lastRequest = time();
  }

HTML 5 Javascript Workers. , , , session_time_out, - .

+2

Source: https://habr.com/ru/post/1782566/


All Articles