Example #1
0
 /**
  * {@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;
 }
 /**
  * @param Message $message
  * @param Ticket $ticket
  */
 private function processWatchers(Message $message, $ticket)
 {
     if (!$ticket) {
         return;
     }
     /** @var Message\MessageRecipient $recipient */
     foreach ($message->getRecipients() as $recipient) {
         $email = $recipient->getEmail();
         if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) {
             continue;
         }
         $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email);
         $oroUser = $this->oroUserManager->findUserByEmail($email);
         if ($oroUser) {
             $user = new User($oroUser->getId(), User::TYPE_ORO);
         } elseif ($diamanteUser) {
             $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE);
         } else {
             $diamanteUser = $this->diamanteUserFactory->create($email, $recipient->getFirstName(), $recipient->getLastName());
             $this->diamanteUserRepository->store($diamanteUser);
             $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE);
         }
         $this->watchersService->addWatcher($ticket, $user);
     }
 }
 /**
  * @param User $user
  *
  * @return bool|OroUser
  */
 public function getOroUser(User $user)
 {
     $user = $this->getByUser($user);
     if ($user instanceof DiamanteUser) {
         $user = $this->oroUserManager->findUserByEmail($user->getEmail());
         if (!$user) {
             return false;
         }
     }
     return $user;
 }