/** * @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()]); }