Exemplo n.º 1
0
 private function handleTheRequest($form, $request)
 {
     $form->handleRequest($request);
     $response = "";
     if ($form->isValid()) {
         $user = new User();
         $user->setUsername($form->get('username')->getViewData());
         $user->setEmail($form->get('email')->getViewData());
         $user->setVoornaam($form->get('voornaam')->getViewData());
         $user->setTussenVoegsels($form->get('tussenVoegsels')->getViewData());
         $user->setAchternaam($form->get('achternaam')->getViewData());
         $user->setAdres($form->get('adres')->getViewData());
         $user->setWoonplaats($form->get('woonplaats')->getViewData());
         $user->setTelefoon($form->get('telefoon')->getViewData());
         $pass = $form->get('password')->getViewData();
         $encoder = $this->container->get('security.password_encoder');
         $encoded = $encoder->encodePassword($user, $pass['Wachtwoord']);
         $user->setPassword($encoded);
         $user->setIsActive(true);
         $em = $this->getDoctrine()->getManager();
         $byUser = $em->getRepository("UserBundle:User")->findOneBy(['username' => $form->get('username')->getViewData()]);
         $byMail = $em->getRepository("UserBundle:User")->findOneBy(['email' => $form->get('email')->getViewData()]);
         if (count($byUser) > 0 || count($byMail) > 0) {
             return "Gebruikersnaam of email bestaat al.";
         }
         //            if($this->admin) {
         //                $role = $em->getRepository('UserBundle:Role')
         //                    ->findOneBy(array(
         //                        "role" => "ROLE_SUPER_ADMIN"
         //                    ));
         //            }else{
         //            }
         $role = $em->getRepository('UserBundle:Role')->findOneBy(array("role" => "ROLE_USER"));
         $user->addRole($role);
         $user->serialize();
         $em->persist($user);
         $em->flush();
         $response = "Succesvol toegevoegd.";
     }
     return $response;
 }