Example #1
0
 /**
  * Close session and save data.
  */
 public function close(Response $response)
 {
     if ($this->id) {
         if ($this->isRefreshReady()) {
             $this->backend->delete($this->id);
             $this->id = TokenGenerator::get();
             $this->data['refreshTime'] = time();
             $this->data['refreshVisits'] = 0;
         }
         $this->data['refreshVisits']++;
         $this->data['lastQuery'] = $this->request->url();
         $this->data['lastTime'] = time();
         $this->backend->save($this->id, $this->data, $this->ttl);
         $response->cookie($this->cookie, $this->id, time() + $this->ttl);
     }
     if (rand() / getrandmax() < $this->gcProbability) {
         $this->backend->clear($this->ttl);
     }
     $this->closed = true;
 }
Example #2
0
 /**
  * Register autologed session for currently authorized user.
  * 
  * @return boolean True, if session will be remembered.
  */
 public function remember(Response $response)
 {
     if (!$this->autologin) {
         throw new \BadMethodCallException('To use AutoLogin functionality provide instance of AutologinProvider.');
     }
     if (!$this->user) {
         return false;
     }
     $key = TokenGenerator::get();
     $this->autologin->add($key, $this->user->getId(), $this->autologinTtl);
     $response->cookie($this->autologinCookie, $key, time() + $this->autologinTtl);
     return true;
 }