コード例 #1
0
 public function refresh(Token $token) : Token
 {
     $newToken = new Token(Uuid::uuid4(), $this->generatePassCode(), $token->getUserUuid(), $this->generateExpires());
     $this->tokenRepository->create($newToken);
     $this->tokenRepository->delete($token);
     return $newToken;
 }
コード例 #2
0
 public function create(Token $token)
 {
     $this->executeSql('
         INSERT INTO tokens (token_uuid, pass_code, user_uuid, expires)
              VALUES (:token_uuid, :pass_code, :user_uuid, :expires)
     ', ['token_uuid' => $token->getUuid()->getBytes(), 'pass_code' => $token->getPassCode(), 'user_uuid' => $token->getUserUuid()->getBytes(), 'expires' => $token->getExpires()->format('Y-m-d H:i:s')]);
 }
コード例 #3
0
 public function it_can_refresh_a_token(Token $token)
 {
     $token->getUserUuid()->willReturn($userUuid = Uuid::uuid4());
     $this->tokenRepository->create(new Argument\Token\TypeToken(Token::class));
     $this->tokenRepository->delete($token);
     $newToken = $this->refresh($token);
     $newToken->shouldHaveType(Token::class);
     $newToken->getUserUuid()->shouldReturn($userUuid);
 }
コード例 #4
0
 public function it_can_insert_a_token(Token $token, \PDOStatement $statement)
 {
     $token->getUuid()->willReturn($uuid = Uuid::uuid4());
     $token->getPassCode()->willReturn($passCode = bin2hex(random_bytes(20)));
     $token->getUserUuid()->willReturn($userUuid = Uuid::uuid4());
     $token->getExpires()->willReturn($expires = new \DateTimeImmutable('+42 seconds'));
     $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO tokens'))->willReturn($statement);
     $statement->execute(['token_uuid' => $uuid->getBytes(), 'pass_code' => $passCode, 'user_uuid' => $userUuid->getBytes(), 'expires' => $expires->format('Y-m-d H:i:s')])->shouldBeCalled();
     $this->create($token);
 }