protected function execute(InputInterface $input, OutputInterface $output) { $login = $input->getArgument("login"); $helper = $this->getHelper('question'); $question = new Question("Unix password for « {$login} » : "); $question->setHidden(true); $question->setHiddenFallback(false); $password = $input->getArgument("password") ? $input->getArgument("password") : $helper->ask($input, $output, $question); $blih = new Blih($login, $password); $blihRepositoriesResponse = $blih->repository()->all(); if ($blihRepositoriesResponse->code == 200) { $user = $this->getUserOrCreateIt($login); $repositoryNames = array_keys(get_object_vars($blihRepositoriesResponse->body->repositories)); foreach ($repositoryNames as $repositoryName) { $output->writeln("> Repository « {$login}/{$repositoryName} »"); $repository = $this->getRepoOrCreateIt($user, $repositoryName); $aclResponse = $blih->repository($repositoryName)->acl()->get(); if ($aclResponse->code == 200) { $acls = get_object_vars($aclResponse->body); foreach ($acls as $aclLogin => $acl) { $output->writeln(" ACL for « {$aclLogin} »: {$acl}"); $aclUser = $this->getUserOrCreateIt($aclLogin); $repositoryACL = $this->getACLOrCreateIt($aclUser, $repository); $repositoryACL->setR(strpos($acl, "r") !== false); $repositoryACL->setW(strpos($acl, "w") !== false); $repositoryACL->setA(strpos($acl, "a") !== false); $this->getContainer()->get("doctrine")->getManager()->persist($repositoryACL); } } $output->writeln(""); $this->getContainer()->get("doctrine")->getManager()->persist($repository); $this->getContainer()->get("doctrine")->getManager()->flush(); } } }
/** * @Security("has_role('ROLE_USER')") * @Template */ public function tokenAction(Request $request) { // Forcing the user the be fully authenticated (the current session must be logged with password) $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); // Manging the UserTokenForm $userTokenForm = $this->createForm("user_token_form", $this->getUser()); $userTokenFormHandler = new FormHandler(); $processed = $userTokenFormHandler->setForm($userTokenForm)->onSuccess(function (FormInterface $userTokenForm) { // Shortcut of the token $token = trim($userTokenForm->getData()->getToken()); if (empty($token) || $token == null) { $userTokenForm->getData()->setToken(null); $this->addFlash("success", "Your Blih token has been removed"); } else { // Testing the token with BLIH before saving it $blih = new Blih($userTokenForm->getData()->getLogin()); $blih->setToken($token); $whoAmI = $blih->whoAmI()->body; // Testing if the token is working if (isset($whoAmI->message) && $whoAmI->message == $userTokenForm->getData()->getLogin()) { $this->addFlash("success", "Your Blih token has been updated"); } else { $this->addFlash("alert", "Your Blih token is not working"); } } })->onAfter(function (FormInterface $userTokenForm) { // Synchronize with the database $this->getDoctrine()->getManager()->persist($userTokenForm->getData()); $this->getDoctrine()->getManager()->flush(); })->process($request); // Redirecting if the form handler has processed if ($processed) { return $this->redirect($this->generateUrl($request->get("_route"))); } return ["userTokenForm" => $userTokenForm->createView()]; }
public function updateUser(User $user) { // If the user has not a token, ignore if ($user->getToken() == null) { return; } // Connecting with Blih $blih = new Blih($user->getLogin()); $blih->setToken($user->getToken()); // Getting the repositories $blihRepositories = $blih->repository()->all()->body; if (!isset($blihRepositories->repositories)) { return; } $blihRepositories = $blihRepositories->repositories; $repositories = $user->getRepositories(); // Removing the repositories removed $repositories->forAll(function ($key, Repository $repository) use($blihRepositories) { if (!array_key_exists($repository->getName(), $blihRepositories)) { $this->entityManager->remove($repository); } return true; }); // Updating or creating the repositories foreach ($blihRepositories as $name => $data) { $repository = $this->retrieveOrCreateRepository($user, $name); $this->updateRepository($repository); $this->entityManager->persist($repository); } // Updating the user $user->setLastRepositoriesUpdateDate(new \DateTime()); $this->entityManager->persist($user); $this->entityManager->flush(); }
/** * Delete a ssh key * * @return array */ public function delete() { return $this->blih->request("DELETE", "/sshkey/" . $this->name); }
/** * Set the ACL rights for an user to a repository * * @param string $login * @param bool $r * @param bool $w * @param bool $a * @return Response */ public function set($login, $r = false, $w = false, $a = false) { $acl = ($r ? 'r' : '') . ($w ? 'w' : '') . ($a ? 'a' : ''); return $this->blih->request("POST", "/repository/" . $this->name . "/acls", ["user" => $login, "acl" => $acl]); }
/** * Delete a repository * * @return Response */ public function delete() { return $this->blih->request("DELETE", "/repository/" . $this->name); }