Пример #1
0
 /**
  * Set the Authtoken cookie and DB-entry. If it's already present, update it.
  *
  * @param Entity\Users $userEntity
  *
  * @return Entity\Authtoken
  */
 protected function updateAuthToken($userEntity)
 {
     $username = $userEntity->getUsername();
     $cookieLifetime = (int) $this->cookieOptions['lifetime'];
     $tokenEntity = $this->getRepositoryAuthtoken()->getUserToken($userEntity->getUsername(), $this->getClientIp(), $this->getClientUserAgent());
     if ($tokenEntity) {
         $token = $tokenEntity->getToken();
     } else {
         $salt = $this->randomGenerator->generateString(32);
         $token = $this->getAuthToken($username, $salt);
         $tokenEntity = new Entity\Authtoken();
         $tokenEntity->setUsername($userEntity->getUsername());
         $tokenEntity->setToken($token);
         $tokenEntity->setSalt($salt);
     }
     $tokenEntity->setValidity(Carbon::create()->addSeconds($cookieLifetime));
     $tokenEntity->setIp($this->getClientIp());
     $tokenEntity->setLastseen(Carbon::now());
     $tokenEntity->setUseragent($this->getClientUserAgent());
     $this->getRepositoryAuthtoken()->save($tokenEntity);
     $this->systemLogger->debug("Saving new login token '{$token}' for user ID '{$username}'", ['event' => 'authentication']);
     return $tokenEntity;
 }
Пример #2
0
 /**
  * Set the Authtoken cookie and DB-entry. If it's already present, update it.
  *
  * @param Entity\Users $userEntity
  *
  * @return Entity\Authtoken
  */
 protected function updateAuthToken($userEntity)
 {
     $salt = $this->randomGenerator->generateString(32);
     if (!($tokenEntity = $this->repositoryAuthtoken->getUserToken($userEntity->getUsername(), $this->remoteIP, $this->userAgent))) {
         $tokenEntity = new Entity\Authtoken();
     }
     $username = $userEntity->getUsername();
     $token = $this->getAuthToken($username, $salt);
     $validityPeriod = $this->cookieOptions['lifetime'];
     $validityDate = new \DateTime();
     $validityInterval = new \DateInterval("PT{$validityPeriod}S");
     $tokenEntity->setUsername($userEntity->getUsername());
     $tokenEntity->setToken($token);
     $tokenEntity->setSalt($salt);
     $tokenEntity->setValidity($validityDate->add($validityInterval));
     $tokenEntity->setIp($this->remoteIP);
     $tokenEntity->setLastseen(new \DateTime());
     $tokenEntity->setUseragent($this->userAgent);
     $this->repositoryAuthtoken->save($tokenEntity);
     $this->systemLogger->debug("Saving new login token '{$token}' for user ID '{$username}'", ['event' => 'authentication']);
     return $tokenEntity;
 }