コード例 #1
0
ファイル: UserProvider.php プロジェクト: Briareos/Undine
 /**
  * {@inheritdoc}
  */
 public function refreshUser(UserInterface $user)
 {
     if (!$user instanceof User) {
         throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
     }
     $refreshedUser = $this->userRepository->find($user->getId());
     if (null === $refreshedUser) {
         throw new UsernameNotFoundException(sprintf('User with ID "%s" not found', $user->getId()));
     }
     return $refreshedUser;
 }
コード例 #2
0
 /**
  * Loads the user for the given token.
  *
  * @param string $token The token.
  *
  * @return UserInterface
  *
  * @throws UsernameNotFoundException If the user is not found.
  */
 public function loadUserByApiToken($token)
 {
     if (!preg_match('{^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})-([0-9a-f]{16,})$}', $token, $matches)) {
         throw new UsernameNotFoundException('The token is invalid.');
     }
     $user = $this->userRepository->find("{$matches['1']}-{$matches['2']}-{$matches['3']}-{$matches['4']}-{$matches['5']}");
     $accessToken = $matches[6];
     if ($user === null) {
         throw new UsernameNotFoundException('User not found.');
     }
     if (!$user->getApiToken()) {
         throw new UsernameNotFoundException('The user does not have token-based API access enabled.');
     }
     if (!hash_equals($user->getApiToken(), $accessToken)) {
         throw new UsernameNotFoundException('User not found.');
     }
     return $user;
 }