/**
* Creates a new User entity.
*
* @param Request $request
* @return RedirectResponse|Response
*/
public function createUserAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
if (!$this->isGranted('CREATE', $journal, 'userRole')) {
throw new AccessDeniedException("You are not authorized for this page!");
}
$entity = new User();
$form = $this->createCreateForm($entity, $journal->getId());
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$formData = $form->getData();
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($entity);
$password = $encoder->encodePassword($entity->getPassword(), $entity->getSalt());
$entity->setPassword($password);
$em->persist($entity);
$journalUser = new JournalUser();
$journalUser->setUser($entity);
$journalUser->setJournal($journal);
if (count($formData->getJournalRoles()) > 0) {
$journalUser->setRoles($formData->getJournalRoles());
}
$em->persist($journalUser);
$em->flush();
$this->successFlashBag('successful.create');
return $this->redirectToRoute('ojs_journal_user_index', ['journalId' => $journal->getId()]);
}
return $this->render('OjsJournalBundle:JournalUser:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
}