Ejemplo n.º 1
0
 /**
  * @param TokenInterface $token
  * @param int            $lifetime
  * @return bool
  */
 public function updateToken(TokenInterface $token, $lifetime)
 {
     if (get_class($token) != static::RECORD || !$token instanceof AbstractToken) {
         throw new InvalidTokenException("Only instances of " . static::RECORD . " is allowed.");
     }
     /**
      * Set new hash, new unique selector, same series.
      * Then delete old token.
      */
     $token->tokenCode = $this->generateHash();
     $token->setField('hash', $this->hashes->makeHash($token->tokenCode));
     $token->setField('selector', $this->generateSelector($token->getSelector()));
     $token->setExpiration(new \DateTime("now + {$lifetime} seconds"));
     if (!$this->save($token)) {
         throw new AuthException("Unable to save token to database");
     }
 }