コード例 #1
0
 public function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
 {
     $connector = new Connector($user->getUsername(), $token->getCredentials());
     if (!$connector->isSignedIn()) {
         throw new BadCredentialsException();
     }
     $student = $connector->getStudent();
     $user->fromStudent($student);
     $user->setLastConnectionAt(new \DateTime());
     if ($user->getId() == null || $user->getAccount() == null) {
         $user->setAccount(new Account());
     }
     $this->em->persist($user);
     $this->em->flush();
 }
コード例 #2
0
ファイル: EpitechUserRetriever.php プロジェクト: Raphy/BlihWI
 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;
 }
コード例 #3
0
ファイル: BlihUpdateCommand.php プロジェクト: Raphy/BlihWI
 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;
 }
コード例 #4
0
ファイル: AdminController.php プロジェクト: Raphy/AfterEpi
 /**
  * @Security("has_role('ROLE_SUPER_ADMIN')")
  * @Template()
  */
 public function editAction(Request $request)
 {
     // Shortcuts
     $em = $this->getDoctrine()->getManager();
     $csrf = $this->get('form.csrf_provider');
     $post = $request->request->all();
     $admin_logger = $this->get('after_epi.admin.logger');
     if ($request->isMethod('POST')) {
         $errors = array();
         if (!array_key_exists('csrf_token', $post) || !$csrf->isCsrfTokenValid('user_edit', $post['csrf_token'])) {
             $errors[0][] = 'La vérification du jeton de sécurité a échoué.';
         }
         if ($request->query->has('id')) {
             if (($user = $em->getRepository('AfterEpiUserBundle:User')->find($request->query->get('id'))) == null) {
                 throw $this->createNotFoundException('User not found');
             }
             if (!array_key_exists('roles', $post) || !is_array($post['roles']) || count($post['roles']) == 0) {
                 $errors[0][] = 'Vous devez mettre au moins 1 droit.';
             }
             if (count($errors) > 0) {
                 return array('user' => $user, 'errors' => $errors, 'post' => $post);
             }
             $user->setRoles($post['roles']);
             $em->persist($user);
             $em->flush();
             $admin_logger->log("Edition de l'utlisateur [" . $user->getId() . "] [" . $user->getLogin() . "]");
             $this->get('session')->getFlashBag()->add('success', "L'utilisateur [" . $user->getLogin() . "] a été modifié.");
             return $this->redirect($this->generateUrl($request->get('_route'), $request->query->all()));
         }
         if (!array_key_exists('login', $post) || empty($post['login'])) {
             $errors['login'] = '******';
         }
         if (!array_key_exists('password', $post) || empty($post['password'])) {
             $errors['password'] = '******';
         }
         if (count($errors) > 0) {
             return array('errors' => $errors, 'post' => $post);
         }
         if (($user = $em->getRepository('AfterEpiUserBundle:User')->findOneBy(array('login' => $post['login']))) != null) {
             $this->get('session')->getFlashBag()->add('info', "Utilisateur [" . $user->getLogin() . "] existe déjà.");
             return $this->redirect($this->generateUrl('afterepi_user_admin_view', array('id' => $user->getId())));
         }
         $connector = new Connector($this->getUser()->getLogin(), $post['password']);
         if (!$connector->isSignedIn()) {
             $this->get('session')->getFlashBag()->add('alert', "Connexion impossible à l'intranet.");
             return $this->redirect($this->generateUrl($request->get('_route')));
         }
         $student = new Student($connector, $request->get('login', null));
         if ($student->getLogin() == null || $student->getFirstName() == null || $student->getLastName() == null) {
             $this->get('session')->getFlashBag()->add('alert', "L'utilisateur [" . $request->get('login', null) . "] est invalide.");
             return $this->redirect($this->generateUrl($request->get('_route')));
         }
         $user = new User();
         $user->fromStudent($student);
         $user->setAccount(new Account());
         $em->persist($user);
         $em->flush();
         $admin_logger->log("Edition de l'utlisateur [" . $user->getId() . "] [" . $user->getLogin() . "]");
         $this->get('session')->getFlashBag()->add('success', "L'utilisateur [" . $user->getLogin() . "] a été ajouté.");
         return $this->redirect($this->generateUrl('afterepi_user_admin_view', array('id' => $user->getId())));
     } else {
         if ($request->query->has('id')) {
             if (($user = $em->getRepository('AfterEpiUserBundle:User')->find($request->query->get('id'))) == null) {
                 throw $this->createNotFoundException('User not found');
             }
             return array('user' => $user);
         }
     }
     return array();
 }