/**
  * Prepare & process form
  *
  * @author Jeremie Samson <*****@*****.**>
  *
  * @return bool
  */
 public function process()
 {
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             /** @var ModelUser $user */
             $user = $this->form->getData();
             if (!$user->getFirstname() || !$user->getLastname() || !$user->getEmailGalaxy() || !$user->getSection()) {
                 $this->form->addError(new FormError('Missing parameter(s)'));
             } else {
                 if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL) || !filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
                     $error = new FormError('email invalid');
                     if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL)) {
                         $this->form->get('email')->addError($error);
                     }
                     if (!filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
                         $this->form->get('emailGalaxy')->addError($error);
                     }
                 } else {
                     $section_id = $this->em->getRepository('FaucondorBundle:Section')->find($user->getSection());
                     $section_code = $this->em->getRepository('FaucondorBundle:Section')->findOneBy(array("code" => $user->getSection()));
                     if (!$section_id && !$section_code) {
                         $this->form->get('section')->addError(new FormError('Section with id ' . $user->getSection() . ' not found'));
                     } else {
                         /** @var Section $section */
                         $section = $section_id ? $section_id : $section_code;
                         $this->onSuccess($user, $section);
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 /**
  * Prepare & process form
  *
  * @author Jeremie Samson <*****@*****.**>
  *
  * @return bool
  */
 public function process()
 {
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             /** @var ModelUserRole $model */
             $model = $this->form->getData();
             if (!$model->getUser() || !$model->getRole()) {
                 $this->form->addError(new FormError('Missing parameter(s)'));
             }
             /** @var User $user */
             $user = $this->em->getRepository('UserBundle:User')->find($model->getUser());
             /** @var Post $role */
             $role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole());
             if (!$user) {
                 $this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found '));
             }
             if (!$role) {
                 $this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found '));
             }
             $this->onSuccess($user, $role);
             return true;
         }
     }
     return false;
 }
 /**
  * Process job configuration form.
  *
  * @param JobConfigurationInterface $configuration
  * @param Request $request
  *
  * @return bool
  */
 public function process(JobConfigurationInterface $configuration, Request $request)
 {
     $this->form->setData($configuration);
     $this->form->handleRequest($request);
     if ($this->form->isValid()) {
         $this->manager->add($configuration);
         return true;
     }
     return false;
 }
 /**
  * @param Order $entity
  *
  * @return bool True when successful processed, false otherwise
  */
 public function process(Order $entity)
 {
     $this->form->setData($entity);
     if ($this->form->handleRequest($this->requestStack->getCurrentRequest())->isValid()) {
         $em = $this->registry->getManagerForClass(Order::class);
         $em->persist($entity);
         $em->flush($entity);
         return true;
     }
     return false;
 }
 /**
  * @param  Request      $request
  * @return JsonResponse
  */
 public function uploadComposerAction(Request $request)
 {
     $this->composerForm->handleRequest($request);
     if ($this->composerForm->isValid()) {
         $data = $this->composerForm->getData();
         $this->sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $data['body'], 'channelName' => $request->getSession()->get('channelName'), 'hasDevDependencies' => $data['hasDevDependencies']));
         return new JsonResponse(array('status' => 'ok'));
     }
     $errors = array_map(function (FormError $error) {
         return $error->getMessage();
     }, $this->composerForm->get('body')->getErrors());
     return new JsonResponse(array('status' => 'ko', 'message' => $errors));
 }
 /**
  * {@inheritdoc}
  */
 public function process($object = null)
 {
     $this->setObject($object);
     if ($this->validateRequest()) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             return $this->onSuccess();
         }
     } elseif (!is_null($this->getObject())) {
         $this->getForm()->setData($this->getObject());
     }
     return false;
 }
 public function changePasswordAction(Request $request)
 {
     $this->changePasswordForm->handleRequest($request);
     if ($this->changePasswordForm->isValid()) {
         $user = $this->tokenStorage->getToken()->getUser();
         $formData = $this->changePasswordForm->getData();
         $this->eventDispatcher->dispatch(AdminSecurityEvents::CHANGE_PASSWORD, new ChangePasswordEvent($user, $formData['plainPassword']));
         $request->getSession()->invalidate();
         $this->tokenStorage->setToken(null);
         $request->getSession()->getFlashBag()->set('success', 'admin.change_password_message.success');
         return new RedirectResponse($this->router->generate('fsi_admin_security_user_login'));
     }
     return $this->templating->renderResponse($this->changePasswordActionTemplate, array('form' => $this->changePasswordForm->createView()));
 }
 public function process()
 {
     $request = $this->getCurrentRequest();
     if (null !== $request) {
         $this->form->setData(new Authorize($request->request->has('accepted'), $request->query->all()));
         if ('POST' === $request->getMethod()) {
             $this->form->handleRequest($request);
             if ($this->form->isValid()) {
                 $this->onSuccess();
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 9
0
 /**
  * @inheritDoc
  */
 public function process(Request $request)
 {
     // Checking if a form has been set
     if ($this->form == null) {
         return false;
     }
     // Processing the handling of the form
     $this->form->handleRequest($request);
     // Shortcuts of the callbacks
     $onBefore = $this->onBeforeCallback;
     $onSuccess = $this->onSuccessCallback;
     $onFailure = $this->onFailureCallback;
     $onAfter = $this->onAfterCallback;
     if ($onBefore != null) {
         $onBefore($this->form);
     }
     $processed = false;
     if ($this->form->isValid()) {
         if ($onSuccess != null) {
             $onSuccess($this->form);
         }
         $processed = true;
     } else {
         if ($onFailure != null) {
             $onFailure($this->form);
         }
     }
     if ($onAfter != null) {
         $onAfter($this->form);
     }
     return $processed;
 }
 /**
  * {@inheritdoc}
  */
 public function process(FormInterface $form, Request $request)
 {
     $valid = false;
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $transUnit = $form->getData();
             $translations = $transUnit->filterNotBlankTranslations();
             // only keep translations with a content
             // link new translations to a file to be able to export them.
             foreach ($translations as $translation) {
                 if (!$translation->getFile()) {
                     $file = $this->fileManager->getFor(sprintf('%s.%s.yml', $transUnit->getDomain(), $translation->getLocale()), $this->rootDir . '/Resources/translations');
                     if ($file instanceof FileInterface) {
                         $translation->setFile($file);
                     }
                 }
             }
             if ($transUnit instanceof PropelTransUnit) {
                 // The setTranslations() method only accepts PropelCollections
                 $translations = new \PropelObjectCollection($translations);
             }
             $transUnit->setTranslations($translations);
             $this->storage->persist($transUnit);
             $this->storage->flush();
             $valid = true;
         }
     }
     return $valid;
 }
 public function handle(FormInterface $form, Request $request)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $data = $form->getData();
     if ($form->isSubmitted()) {
         $user = $this->userManager->findUserByEmail($data['email']);
         if (is_null($user)) {
             $form->addError(new FormError($this->translator->trans('security.resetting.request.errors.email_not_found')));
             return false;
         }
         if ($user->isPasswordRequestNonExpired($this->tokenTll)) {
             $form->addError(new FormError($this->translator->trans('security.resetting.request.errors.password_already_requested')));
             return false;
         }
         if ($user->getConfirmationToken() === null) {
             $user->setConfirmationToken($this->tokenGenerator->generateToken());
         }
         $user->setPasswordRequestedAt(new \DateTime());
         $this->userManager->resettingRequest($user);
     }
     return true;
 }
 /**
  * @param FormInterface $form
  * @param Request $request
  * @return bool
  */
 private function handle(FormInterface $form, Request $request)
 {
     $form->handleRequest($request);
     if ($form->isValid()) {
         return true;
     }
     return false;
 }
Esempio n. 13
0
 /**
  * @param Badge $badge
  *
  * @return bool True on successfull processing, false otherwise
  */
 public function handleEdit(Badge $badge, $badgeManager = null, $unawardBadge = false)
 {
     $this->form->setData($badge);
     /** @var BadgeRule[]|\Doctrine\Common\Collections\ArrayCollection $originalRules */
     $originalRules = $badge->getRules();
     if ($this->request->isMethod('POST')) {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             $this->handleUpload($this->form->get('file')->getData(), $badge);
             $badgeRules = $badge->getRules();
             $userBadges = $badge->getUserBadges();
             if (0 < count($userBadges) && $this->badgeManager->isRuleChanged($badgeRules, $originalRules)) {
                 /** @var \Doctrine\ORM\UnitOfWork $unitOfWork */
                 $unitOfWork = $this->entityManager->getUnitOfWork();
                 $newBadge = clone $badge;
                 $newBadge->setVersion($badge->getVersion() + 1);
                 $unitOfWork->refresh($badge);
                 $badge->setDeletedAt(new \DateTime());
                 $this->entityManager->persist($newBadge);
                 // If the new badge has to be revoked from users already awarded, skip the next part
                 if (!$unawardBadge) {
                     foreach ($userBadges as $userBadge) {
                         // Award new version to previous users
                         $badgeManager->addBadgeToUser($newBadge, $userBadge->getUser());
                     }
                 }
             } else {
                 // Compute which rules was deleted
                 foreach ($badgeRules as $rule) {
                     if ($originalRules->contains($rule)) {
                         $originalRules->removeElement($rule);
                     }
                 }
                 // Delete rules
                 foreach ($originalRules as $rule) {
                     $this->entityManager->remove($rule);
                 }
             }
             $this->entityManager->persist($badge);
             $this->entityManager->flush();
             return true;
         }
     }
     return false;
 }
Esempio n. 14
0
 /**
  * @param Request $request
  * @param $form
  * @return FormView, bool
  */
 public function valid(Request $request, FormInterface $form)
 {
     $isValid = false;
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         $isValid = $form->isValid();
     }
     return [$form->createView(), $isValid];
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $this->handler->updateCredentials($form->getData()->getUser(), $form->getData()->getNewPassword());
     return true;
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $this->handler->createUser($form->getData()->getUser());
     return true;
 }
Esempio n. 17
0
 /**
  * @param FormInterface $form
  * @param Request $request
  * @return bool
  */
 protected function isFormSubmitted(FormInterface $form, Request $request)
 {
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         return $form->isSubmitted();
     } else {
         return false;
     }
 }
 /**
  * @param Request       $request
  * @param FormInterface $form
  *
  * @return Response|null
  */
 private function handleCreateGameForm(Request $request, FormInterface $form, CreateGameForm $formObject)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $gameId = $this->gameService->createGame($formObject->getName());
         return $this->redirectToRoute(self::ROUTE_GAME_DETAIL, ['gameId' => $gameId]);
     }
     return;
 }
 public function handle(FormInterface $form, Request $request)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $entity = $form->getData();
     $this->userManager->resettingReset($entity);
     $this->flashBag->add(FlashBagEvents::MESSAGE_TYPE_SUCCESS, $this->translator->trans('security.resetting.reset.success'));
     return true;
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $token = $request->query->get('token');
     $user = $this->handler->getUserByConfirmationToken($token);
     $this->handler->clearConfirmationTokenUser($user);
     $this->handler->updateCredentials($user, $form->getData()->getPassword());
     return true;
 }
Esempio n. 21
0
 /**
  * @return Response|null
  */
 private function handleGameDetailForm(Request $request, FormInterface $form, GameDetailForm $formObject)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid() && !$form->get('dealGame')->isClicked()) {
         throw new BadRequestHttpException('invalid or missing submit action');
     }
     if ($form->isSubmitted() && $form->isValid() && $form->get('dealGame')->isClicked()) {
         $this->gameService->deal($formObject->getGameId());
         return $this->redirectToRoute(self::ROUTE_GAME_DETAIL, ['gameId' => $formObject->getGameId()]);
     }
     return;
 }
Esempio n. 22
0
 /**
  * {@inheritdoc}
  */
 public function handle(FormInterface $form, Request $request)
 {
     if ($request->isMethod($this->requestMethod)) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $event = new FormEvent($form, $request);
             $this->eventDispatcher->dispatch(PostEvents::FORM_VALID, $event);
             return true;
         }
     }
     return false;
 }
 /**
  * @return array|mixed
  */
 protected function getCriteriaFromForm()
 {
     $criteria = [];
     if (null === $this->form) {
         return $criteria;
     }
     $this->form->handleRequest($this->request);
     if ($this->form->isSubmitted() && $this->form->isValid() || !$this->form->isSubmitted()) {
         $criteria = ArrayHelper::arrayForce($this->form->getData());
     }
     return $criteria;
 }
Esempio n. 24
0
 /**
  * @param Request       $request
  * @param FormInterface $form
  *
  * @param Page          $page
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function processPageForm(Request $request, $form, $page = null)
 {
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $page = $form->getData();
         $em = $this->get('doctrine.orm.entity_manager');
         $em->persist($page);
         $em->flush();
         return $this->redirect($this->generateUrl('taforum_admin_page', array('pagePermalink' => $page->getPagePermalink())));
     }
     return $this->render('TerAelisForumBundle:Page:admin_page_edit.html.twig', array('page' => !empty($page) ? $page : null, 'form' => $form->createView()));
 }
 /**
  * Processes the form only for POST requests. It passes the current request to the form, and checks if form is valid.
  * If everything is okay, return value is the data object, otherwise an appropriate exception is thrown.
  * @param AbstractType|string $formType Pass the instance of the form. If you pass form name as a string, Factory will handle the creating in that case.
  * @param null $entity
  * @param array $options
  * @return mixed
  * @throws FormHandlerException
  * @throws FormValidationException
  */
 public function process($formType, $entity = null, array $options = array())
 {
     try {
         $this->form = $this->formFactory->createNamed(null, $formType, $entity, $options);
     } catch (TransformationFailedException $e) {
         throw (new FormValidationException())->setError($e->getMessage());
     }
     if ($this->request->getMethod() === 'POST') {
         try {
             $this->form->handleRequest($this->request);
         } catch (FormHandleRequestException $e) {
             throw (new FormValidationException())->setError($e->getField(), $e->getFieldMessage());
         } catch (UnexpectedValueException $e) {
             throw (new FormValidationException())->setError($e->getMessage());
         }
         if ($this->form->isValid()) {
             return $this->form->getData();
         }
         throw (new FormValidationException())->setErrors($this->getAllFormErrors($this->form));
     }
     throw new FormHandlerException('Form handler requires a POST method.');
 }
 /**
  * {@inheritdoc}
  */
 public function processForm(FormInterface $form, Request $request)
 {
     $valid = false;
     $form->handleRequest($request);
     if ($form->isValid()) {
         $model = $form->getData();
         $model->getEntity()->addTranslation($model->getTranslation());
         $this->em->persist($model->getEntity());
         $this->em->flush();
         $valid = true;
     }
     return $valid;
 }
Esempio n. 27
0
 /**
  * Processing of form reload.
  */
 protected function processReload()
 {
     $this->form->handleRequest($this->request);
     $type = $this->form->get('processType')->getViewData();
     /** @var Mailbox $data */
     $data = $this->form->getData();
     if (!empty($type)) {
         $processorEntity = $this->mailboxProcessStorage->getNewSettingsEntity($type);
         $data->setProcessSettings($processorEntity);
     } else {
         $data->setProcessSettings(null);
     }
     $this->form = $this->formFactory->create(self::FORM, $data);
 }
 /**
  * Handle form request.
  *
  * @param \Symfony\Component\Form\FormInterface     $form
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request)
 {
     $this->logger->info('UserEditFormHandler handle()');
     if (!$request->isMethod('POST')) {
         return false;
     }
     $form->handleRequest($request);
     if (!$form->isValid()) {
         $this->flashManager->getErrorMessage();
         return false;
     }
     $this->userManager->update($form->getData());
     $this->flashManager->getSuccessMessage('update successfully!');
     return true;
 }
Esempio n. 29
0
 /**
  * @param Request $request
  * @param FormInterface $form
  */
 public function process(Request $request, FormInterface $form)
 {
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $idea = new IdeaEntity();
         $idea->setTitle($data['title'])->setDescription($data['description'])->setUser($this->getUserFromTokenStorage());
         $this->ideaService->saveIdea($idea);
         if ($data['youtube-flag'] === true) {
             $youtubeLink = new Link();
             $youtubeLink->setIdea($idea)->setType(Link::TYPE_YOUTUBE)->setLink($data['youtube-value']);
             $this->linkService->saveLink($youtubeLink);
         }
     }
 }
 /**
  * @param Request       $request
  * @param FormInterface $form
  *
  * @return bool
  */
 public function handle(Request $request, FormInterface $form)
 {
     $this->logger->info('ForgotPasswordFormHandler handle()');
     if (!$request->isMethod('POST')) {
         return false;
     }
     $form->handleRequest($request);
     if (!$form->isValid()) {
         $this->flashManager->getErrorMessage();
         return false;
     }
     $user = $form->getData();
     $this->userManager->resetPassword($user);
     $this->flashManager->getSuccessMessage('Your password was changed successfully!');
     return true;
 }