public function onPostAuthorizationProcess(OAuthEvent $event) { if (!$event->isAuthorizedClient()) { return; } if (null === ($client = $event->getClient())) { return; } $user = $this->getUser($event); $scope = $this->getScope(); $em = $this->doctrine->getManager(); $authRepo = $em->getRepository('LoginCidadaoCoreBundle:Authorization'); $currentAuth = $authRepo->findOneBy(array('person' => $user, 'client' => $client)); // if the authorization is already there, update it. if ($currentAuth instanceof Authorization) { $merged = array_merge($currentAuth->getScope(), $scope); $currentAuth->setScope($merged); } else { $authorization = new Authorization(); $authorization->setClient($client); $authorization->setPerson($user); $authorization->setScope($scope); $em->persist($authorization); } $em->flush(); }
private function getClientCount(ClientRepository $clientRepo, Authorization $entity) { $counts = $clientRepo->getCountPerson($entity->getPerson(), $entity->getClient()->getId()); if (count($counts) > 0) { $count = $counts[0]['qty']; } else { $count = 0; } if (!is_int($count)) { $count = 0; } return $count; }
public function onRegistrationCompleted(FilterUserResponseEvent $event) { $user = $event->getUser(); $auth = new Authorization(); $auth->setPerson($user); $auth->setClient($this->clientRepository->findOneBy(['uid' => $this->defaultClientUid])); $auth->setScope(explode(' ', $this->lcSupportedScopes)); $this->em->persist($auth); $this->em->flush(); $this->mailer->sendConfirmationEmailMessage($user); if (strlen($user->getPassword()) == 0) { // TODO: DEPRECATE NOTIFICATIONS // TODO: create an optional task offering users to set a password //$this->notificationsHelper->enforceEmptyPasswordNotification($user); } $this->registerRequestedScope->clearRequestedScope($event->getRequest()); }