src/Bse/CandidatureBundle/Controller/CandidatureController.php
/**
     * Creates a new Candidature entity.
     *
     */
Creates a new Candidature entity.
Creates a new Candidature entity .
public function createAction(Request $request)
    {
        $entity = new Candidature();
        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);
        $data = $form->getData();
        $email = $form->get('email')->getData();
        $userFoundUsingEmail = $this->get('fos_user.user_manager')->findUserByEmail($email);
        if($userFoundUsingEmail != null){
            return $this->render('BseCandidatureBundle:Candidature:new.html.twig', array(
                'entity' => $entity,            
                'form'   => $form->createView(),                    
                'emailAlreadyInUse' => $email,
                'filieresData' => ArrayData::getFilieresData($this->container),
                'paysData' => ArrayData::getPaysData($this->get('kernel')),
                'villesData' => ArrayData::getVillesData($this->get('kernel')),
                'systemesData' => ArrayData::getSystemesData(),
                'mentionsData' => ArrayData::getMentionsData(),
                'etablissementsData' => ArrayData::getEtablissementsData($this->get('kernel')),
                'typesDiplomeData' => ArrayData::getTypesDiplomeData(),
                'intitulesDiplomeData' => ArrayData::getIntitulesDiplomeData($this->get('kernel')),
                'facultesData' => ArrayData::getFacultesData()        
            ));
        }              
        if ($form->isValid()) {
            $userManager = $this->container->get('fos_user.user_manager');
            $user = $userManager->createUser();
            $user->setUsername($form->get('email')->getData());
            $user->setEmail($form->get('email')->getData());
            $user->setPlainPassword($form->get('motDePasse')->getData());
            $user->setEnabled(true);
            $userManager->updateUser($user);
            $this->getDoctrine()->getManager()->flush();
            $entity->setFosuserId($user->getId());  
            $em = $this->getDoctrine()->getManager();            
            $em->persist($entity);
            $em->flush();
            try {
                $this->container->get('fos_user.security.login_manager')->loginUser(
                    $this->container->getParameter('fos_user.firewall_name'),
                    $user);
            } catch (AccountStatusException $ex) {
            }
            $this->get('session')->getFlashBag()->add('notice', 'Votre candidature a été créée correctement !');
            return $this->redirect($this->generateUrl('candidature'));
        }
        return $this->render('BseCandidatureBundle:Candidature:new.html.twig', array(
            'entity' => $entity,            
            'form'   => $form->createView(), 
            'filieresData' => ArrayData::getFilieresData($this->container),
            'paysData' => ArrayData::getPaysData($this->get('kernel')),
            'villesData' => ArrayData::getVillesData($this->get('kernel')),
            'systemesData' => ArrayData::getSystemesData(),
            'mentionsData' => ArrayData::getMentionsData(),
            'etablissementsData' => ArrayData::getEtablissementsData($this->get('kernel')),
            'typesDiplomeData' => ArrayData::getTypesDiplomeData(),
            'intitulesDiplomeData' => ArrayData::getIntitulesDiplomeData($this->get('kernel')),
            'facultesData' => ArrayData::getFacultesData()           
        ));
    }
public function createAction ( Request $ request ) { $ entity = new Candidature ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; $ form -> handleRequest ( $ request ) ; $ data = $ form -> getData ( ) ; $ email = $ form -> get ( 'email' ) -> getData ( ) ; $ userFoundUsingEmail = $ this -> get ( 'fos_user.user_manager' ) -> findUserByEmail ( $ email ) ; if ( $ userFoundUsingEmail != null ) { return $ this -> render ( 'BseCandidatureBundle:Candidature:new.html.twig' , array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , 'emailAlreadyInUse' => $ email , 'filieresData' => ArrayData :: getFilieresData ( $ this -> container ) , 'paysData' => ArrayData :: getPaysData ( $ this -> get ( 'kernel' ) ) , 'villesData' => ArrayData :: getVillesData ( $ this -> get ( 'kernel' ) ) , 'systemesData' => ArrayData :: getSystemesData ( ) , 'mentionsData' => ArrayData :: getMentionsData ( ) , 'etablissementsData' => ArrayData :: getEtablissementsData ( $ this -> get ( 'kernel' ) ) , 'typesDiplomeData' => ArrayData :: getTypesDiplomeData ( ) , 'intitulesDiplomeData' => ArrayData :: getIntitulesDiplomeData ( $ this -> get ( 'kernel' ) ) , 'facultesData' => ArrayData :: getFacultesData ( ) ) ) ; } if ( $ form -> isValid ( ) ) { $ userManager = $ this -> container -> get ( 'fos_user.user_manager' ) ; $ user = $ userManager -> createUser ( ) ; $ user -> setUsername ( $ form -> get ( 'email' ) -> getData ( ) ) ; $ user -> setEmail ( $ form -> get ( 'email' ) -> getData ( ) ) ; $ user -> setPlainPassword ( $ form -> get ( 'motDePasse' ) -> getData ( ) ) ; $ user -> setEnabled ( true ) ; $ userManager -> updateUser ( $ user ) ; $ this -> getDoctrine ( ) -> getManager ( ) -> flush ( ) ; $ entity -> setFosuserId ( $ user -> getId ( ) ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; try { $ this -> container -> get ( 'fos_user.security.login_manager' ) -> loginUser ( $ this -> container -> getParameter ( 'fos_user.firewall_name' ) , $ user ) ; } catch ( AccountStatusException $ ex ) { } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'notice' , 'Votre candidature a été créée correctement !'); return $ this -> redirect ( $ this -> generateUrl ( 'candidature' ) ) ; } return $ this -> render ( 'BseCandidatureBundle:Candidature:new.html.twig' , array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , 'filieresData' => ArrayData :: getFilieresData ( $ this -> container ) , 'paysData' => ArrayData :: getPaysData ( $ this -> get ( 'kernel' ) ) , 'villesData' => ArrayData :: getVillesData ( $ this -> get ( 'kernel' ) ) , 'systemesData' => ArrayData :: getSystemesData ( ) , 'mentionsData' => ArrayData :: getMentionsData ( ) , 'etablissementsData' => ArrayData :: getEtablissementsData ( $ this -> get ( 'kernel' ) ) , 'typesDiplomeData' => ArrayData :: getTypesDiplomeData ( ) , 'intitulesDiplomeData' => ArrayData :: getIntitulesDiplomeData ( $ this -> get ( 'kernel' ) ) , 'facultesData' => ArrayData :: getFacultesData ( ) ) ) ; }
Creates a new Candidature entity.
Creates a new Candidature entity .
//$firstCandidature = $request->request->get('firstCandidature'); // check if email is already in use             // create a new user // make more modifications to the database // bind new entity to created user // autheticate the user  // We simply do not authenticate users which do not pass the user // checker (not enabled, expired, etc.).