コード例 #1
0
 /**
  * @param User|null      $user
  * @param string         $type
  * @param \DateTime|null $expiration
  * @param mixed|null     $data
  *
  * @return Token
  */
 public function create(User $user = null, $type, \DateTime $expiration = null, $data = null)
 {
     $this->removeExpiredTokens();
     $n = 0;
     do {
         if ($n++ > 1024) {
             throw new \RuntimeException('Unable to create a token.');
         }
         $value = $this->random->generateString(32, self::LETTERS_AND_NUMBERS);
         $found = null !== $this->om->getRepository('Phraseanet:Token')->find($value);
     } while ($found);
     $token = new Token();
     $token->setUser($user)->setType($type)->setValue($value)->setExpiration($expiration)->setData($data);
     $this->om->persist($token);
     $this->om->flush();
     return $token;
 }
コード例 #2
0
 private function insertOneValidationToken(EntityManager $em, \Pimple $DI)
 {
     $user = $DI['user'];
     $token = new Token();
     $token->setValue($this->container['random.low']->generateString(12, TokenManipulator::LETTERS_AND_NUMBERS));
     $token->setUser($user);
     $token->setType(TokenManipulator::TYPE_VALIDATE);
     $token->setData($DI['basket_1']->getId());
     $DI['token_validation'] = $token;
     $em->persist($token);
 }