Esempio n. 1
0
 public function load(ObjectManager $manager)
 {
     $role = new Role();
     $role->setRole('staff');
     $user = new User();
     $user->setUsername('Test');
     $user->setPlainPassword('hello');
     $user->setPassword('test');
     $user->setRole($role);
     $user->setEmail('*****@*****.**');
     $user->setIsActive(false);
     $role->addUser($user);
     $manager->persist($role);
     $manager->flush();
 }
Esempio n. 2
0
 public function registerAction(Request $request)
 {
     $path = $request->getPathInfo();
     $role = $this->generateRole($path);
     $user = new User();
     $user->setRole($role);
     $role->addUser($user);
     $form = $this->createForm(RoleType::class, $role);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $data = $form->getData();
         $role = $data->getRole();
         $users = $data->getUsers();
         foreach ($users as $user) {
             $password = $this->get('security.password_encoder')->encodePassword($user, $user->getPlainPassword());
             $user->setPassword($password);
             $user->setRole($role);
             $em->persist($user);
         }
         $em->flush();
     }
     return $this->render('POSBundle:Default:register.html.twig', array('form' => $form->createView()));
 }