/** * @param $username * * @return UserInterface * @throws UsernameNotFoundException */ public function loadUserByUsername($username) { $user = $this->userRepository->findOneBy(['username' => $username]); if (!$user) { throw new UsernameNotFoundException(sprintf('User with username: %s not found', $username)); } return $user; }
/** * Loads the user for the given username. * * This method must throw UsernameNotFoundException if the user is not * found. * * @param string $username The username * * @return UserInterface * * @see UsernameNotFoundException * * @throws UsernameNotFoundException if the user is not found */ public function loadUserByUsername($username) { $user = $this->userRepository->findOneBy(['username' => $username]); if (!is_null($user)) { return $user; } else { $message = sprintf('Unable to find an active admin AppBundle:User object identified by "%s".', $username); throw new UsernameNotFoundException($message, 0); } }