Example #1
0
 public function load(ObjectManager $manager)
 {
     $utilisateur1 = new User();
     $utilisateur1->setUsername('admin')->setEmail('*****@*****.**')->setEnabled(1)->addRole("ROLE_ADMIN")->setPassword($this->container->get('security.encoder_factory')->getEncoder($utilisateur1)->encodePassword('admin', $utilisateur1->getSalt()));
     $manager->persist($utilisateur1);
     $utilisateur2 = new User();
     $utilisateur2->setUsername('super')->setEmail('*****@*****.**')->setEnabled(1)->setPassword($this->container->get('security.encoder_factory')->getEncoder($utilisateur2)->encodePassword('super', $utilisateur2->getSalt()));
     $manager->persist($utilisateur2);
     $group = new Group("administrateurs", array('ROLE_ADMIN'));
     $manager->persist($group);
     $manager->persist($utilisateur1->addGroup($group));
     $group = new Group("Super administrateur", array('ROLE_SUPER_ADMIN'));
     $manager->persist($group);
     $manager->persist($utilisateur2->addGroup($group));
     $manager->flush();
     $this->addReference('utilisateur1', $utilisateur1);
     $this->addReference('utilisateur2', $utilisateur2);
 }
 public function addUserAction(Client $client)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     if (is_null($client->getUser())) {
         $user = new User();
         $user->setEmail($client->getEmail());
         $form = $this->createForm(new RegistrationFormType(), $user, array('validation_groups' => array('Registration')))->remove('groups');
     } else {
         $user = $client->getUser();
         $form = $this->createForm(new RegistrationFormType(), $user, array('validation_groups' => array('Profile')))->remove('plainPassword')->remove('groups');
     }
     if ($this->getRequest()->isMethod('POST')) {
         $form->submit($this->getRequest());
         if ($form->isValid()) {
             $user = $form->getData();
             $em->persist($user->setEnabled(TRUE)->setClient($client));
             $em->flush();
             $session->getFlashBag()->add('success', " Client traité avec succès ");
             return $this->redirect($this->generateUrl('back_crm_client_profil_user', array('id' => $client->getId())));
         }
     }
     return $this->render('BackUserBundle:client:profil\\user.html.twig', array('form' => $form->createView(), 'client' => $client));
 }
Example #3
0
 public function enableUserAction(User $user)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     if ($user->isEnabled()) {
         $user->setEnabled(false);
     } else {
         $user->setEnabled(true);
     }
     $em->persist($user);
     $em->flush();
     $session->getFlashBag()->add('success', "Votre utilisateur a été modifié avec succées");
     return $this->redirect($this->generateUrl("user"));
 }