Baikal\AdminBundle\Controller\User\FormController::newAction PHP Метод

newAction() публичный Метод

public newAction ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function newAction(Request $request)
    {
        $form = $this->get('form.factory')->create(new FormType\User\CreateUserType());
        $form->handleRequest($request);
        if ($form->isValid()) {
            $data = $form->getData();
            $em = $this->getDoctrine()->getManager();
            # Persisting identity principal
            $principalidentity = new UserPrincipal();
            $principalidentity->setDisplayname($data['displayname']);
            $principalidentity->setUri('principals/' . $data['username']);
            $principalidentity->setEmail($data['email']);
            $em->persist($principalidentity);
            # Persisting user
            $user = new User();
            $user->setUsername($data['username']);
            $user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($data['password'], $user->getSalt()));
            foreach ($data['roles'] as $role) {
                $user->addRole($role);
            }
            $em->persist($user);
            $em->flush();
            $this->get('session')->getFlashBag()->add('notice', 'User <i class="fa fa-user"></i> <strong>' . htmlspecialchars($user->getUsername()) . '</strong> has been created.');
            return $this->redirect($this->generateUrl('baikal_admin_user_list'));
        }
        return $this->render('BaikalAdminBundle:User:form.html.twig', array('form' => $form->createView()));
    }