/** * {@inheritdoc} */ public function loadUserByOAuthUserResponse(UserResponseInterface $response) { if (!$this->cm->get('oro_sso.enable_google_sso')) { throw new \Exception('SSO is not enabled'); } $username = $response->getUsername(); if ($username === null) { throw new BadCredentialsException('Bad credentials'); } if (!$this->isEmailEnabledForOauth($response->getEmail())) { throw new EmailDomainNotAllowedException('Bad credentials'); } $user = $this->userManager->findUserBy([$this->getOAuthProperty($response) => $username]); if (!$user) { $user = $this->userManager->findUserByEmail($response->getEmail()); if ($user) { $user->setGoogleId($username); $this->userManager->updateUser($user); } } if (!$user || !$user->isEnabled()) { throw new BadCredentialsException('Bad credentials'); } return $user; }
/** * {@inheritDoc} */ public function refreshUser(SecurityUserInterface $user) { if (!$user instanceof User) { throw new UnsupportedUserException(sprintf('Expected an instance of Oro\\Bundle\\UserBundle\\Entity\\User, but got "%s".', get_class($user))); } if (null === ($reloadedUser = $this->userManager->findUserBy(array('id' => $user->getId())))) { throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $user->getId())); } return $reloadedUser; }
/** * @param $email * * @return DiamanteUser|OroUser */ public function getUserInstanceByEmail($email) { $oroUser = $this->oroUserManager->findUserBy(['email' => $email]); if ($oroUser) { return $oroUser; } $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email); if ($diamanteUser) { return $diamanteUser; } throw new \RuntimeException('User loading failed. User not found'); }
/** * @param $email * @return User|null */ public function getUserByEmail($email) { $oroUser = $this->oroUserManager->findUserBy(['email' => $email]); $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email); if ($oroUser) { return new User($oroUser->getId(), User::TYPE_ORO); } if ($diamanteUser) { return new User($diamanteUser->getId(), User::TYPE_DIAMANTE); } return null; }
public function testFindUserBy() { $crit = array('id' => 0); $this->repository->expects($this->once())->method('findOneBy')->with($this->equalTo($crit))->will($this->returnValue(array())); $this->userManager->findUserBy($crit); }
/** * @param Notification $notification * @return void */ public function notify(Notification $notification) { if (!$this->container->isScopeActive('request')) { $this->container->enterScope('request'); $this->container->set('request', new Request(), 'request'); } $ticket = $this->loadTicket($notification); $changeList = $this->postProcessChangesList($notification); foreach ($this->watchersService->getWatchers($ticket) as $watcher) { $userType = $watcher->getUserType(); $user = User::fromString($userType); $isOroUser = $user->isOroUser(); if ($isOroUser) { $loadedUser = $this->oroUserManager->findUserBy(['id' => $user->getId()]); } else { $loadedUser = $this->diamanteUserRepository->get($user->getId()); } $message = $this->message($notification, $ticket, $isOroUser, $loadedUser->getEmail(), $changeList); $this->mailer->send($message); $reference = new MessageReference($message->getId(), $ticket); $this->messageReferenceRepository->store($reference); } }