/**
  * @Route("/goin/{name}/{id}", defaults={"name"="hola", "id"="adios"})
  * @Route("/goin/{name}/{id}", name="goin")
  * @Security("has_role('ROLE_ADMIN')")
  */
 public function camoninAction($name, $id)
 {
     $login = new Login();
     $login->setName($name);
     $login->setPasswd($id);
     $normalizer = new GetSetMethodNormalizer();
     $encoder = new JsonEncoder();
     $serializer = new Serializer(array($normalizer), array($encoder));
     $json = $serializer->serialize(array('name' => $login->getName(), 'pass' => $login->getPasswd()), 'json');
     // Output: {"name":"foo","sportsman":false}
     $response = new Response($json);
     $response->headers->set('Access-Control-Allow-Origin', '*');
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 /**
  * @Route("/group/{groupid}/new", name="new_login")
  */
 public function newLogin(Request $request, $groupid)
 {
     $login = new Login();
     $groupRepo = $this->getDoctrine()->getManager()->getRepository('AppBundle:Groups');
     $group = $groupRepo->findOneById($groupid);
     //$this->denyAccessUnlessGranted('view', $group);
     if ($group == null || !$this->isGranted('view', $group)) {
         $this->addFlash('error', $this->get('translator')->trans("You don't have access to this group"));
         return $this->redirectToRoute('groups');
     }
     $login->setGroup($group);
     $form = $this->createForm(LoginType::class, $login, ['groups_repository' => $this->getDoctrine()->getEntityManager()->getRepository('AppBundle:Groups'), 'current_user' => $this->get('security.token_storage')->getToken()->getUser()]);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         // With login, we need to encrypt the password to save it
         $this->get('appbundle.field_protect')->encryptLoginPassword($login, $form->get('plainPassword')->getData());
         $em = $this->getDoctrine()->getManager();
         $em->persist($login);
         $em->flush();
         return $this->redirectToRoute('logins', ['groupid' => $login->getGroup()->getId()]);
     }
     return $this->render('AppBundle:Default:login.html.twig', ['form' => $form->createView()]);
 }
 public function decryptLoginPassword(Login $login)
 {
     $groupKey = $this->keyProtect->getGroupKey($login->getGroup());
     return $this->decryptProtected($groupKey, $login->getPassword());
 }