Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedComputerManagerInterface::addTrustedComputer PHP Méthode

addTrustedComputer() public méthode

Add a trusted computer token for a user.
public addTrustedComputer ( mixed $user, string $token, DateTime $validUntil )
$user mixed
$token string
$validUntil DateTime
    public function addTrustedComputer($user, $token, \DateTime $validUntil);

Usage Example

 /**
  * Create a cookie for trusted computer.
  *
  * @param Request $request
  * @param mixed   $user
  *
  *
  * @return Cookie
  */
 public function createTrustedCookie(Request $request, $user)
 {
     $tokenList = $request->cookies->get($this->cookieName, null);
     // Generate new token
     $token = $this->tokenGenerator->generateToken(32);
     $tokenList .= ($tokenList !== null ? ';' : '') . $token;
     $validUntil = $this->getDateTimeNow()->add(new \DateInterval('PT' . $this->cookieLifetime . 'S'));
     // Add token to user entity
     $this->trustedComputerManager->addTrustedComputer($user, $token, $validUntil);
     $domain = null;
     $requestHost = $request->getHost();
     if ($requestHost !== 'localhost') {
         $domain = '.' . $requestHost;
     }
     // Create cookie
     return new Cookie($this->cookieName, $tokenList, $validUntil, '/', $domain, $this->cookieSecure);
 }
TrustedComputerManagerInterface