public function retrieve($login)
 {
     // Creating or retrieving the user
     $user = $this->entityManager->getRepository("AppBundle:User")->findOneByLogin($login);
     if ($user == null) {
         $user = new User();
         $user->setLogin($login);
     }
     // Updating from Intranet
     $connector = new Connector();
     $connector->authenticate(Connector::SIGN_IN_METHOD_CREDENTIALS, $this->connectorParameters["login"], $this->connectorParameters["password"]);
     if (!$connector->isSignedIn()) {
         throw new \Exception();
     }
     $intranetUser = new \EpitechAPI\Component\User($connector, $user->getLogin());
     $user->updateFromIntranet($intranetUser);
     return $user;
 }
Exemple #2
0
 protected function getUserOrCreateIt($login)
 {
     if (($user = $this->getContainer()->get("doctrine")->getManager()->getRepository("AppBundle:User")->findOneByLogin($login)) == null) {
         $user = new User();
         $user->setLogin($login);
         $connector = new Connector();
         $connector->authenticate(Connector::SIGN_IN_METHOD_CREDENTIALS, $this->getContainer()->getParameter("connector")["login"], $this->getContainer()->getParameter("connector")["password"]);
         if ($connector->isSignedIn() == false) {
             throw new \RuntimeException("Intranet is not responding");
         }
         $student = new \EpitechAPI\Component\User($connector, $login);
         $user->updateFromIntranet($student);
         $this->getContainer()->get("doctrine")->getManager()->persist($user);
         $this->getContainer()->get("doctrine")->getManager()->flush();
     }
     return $user;
 }