/**
  * @param UserEvent $event
  * @throws \Exception
  * @throws \Twig_Error
  */
 public function onResettingRequestSuccess(UserEvent $event)
 {
     $user = $event->getUser();
     $params = $event->getParams();
     $url = $this->router->generate($params[$event::PARAM_RESETTING_EMAIL_ROUTE], array('token' => $user->getConfirmationToken()), true);
     $message = \Swift_Message::newInstance()->setSubject($this->translator->trans('security.resetting.request.email.subject'))->setFrom($this->parameter->get($params[$event::PARAM_RESETTING_EMAIL_FROM]))->setTo($user->getEmail())->setBody($this->twigEngine->render($params[$event::PARAM_RESETTING_EMAIL_TEMPLATE], array('complete_name' => $event->getSecureArea()->getCompleteName(), 'url' => $url)));
     $this->mailer->send($message);
     $this->flashBag->add(FlashBagEvents::MESSAGE_TYPE_SUCCESS, $this->translator->trans('security.resetting.request.check_email', array('user_email' => $user->getObfuscatedEmail())));
 }
 protected function setUp()
 {
     $this->attributes = new AttributeBag();
     $this->flashes = new FlashBag();
     $this->data = array($this->attributes->getStorageKey() => array('foo' => 'bar'), $this->flashes->getStorageKey() => array('notice' => 'hello'));
     $this->storage = new MockArraySessionStorage();
     $this->storage->registerBag($this->flashes);
     $this->storage->registerBag($this->attributes);
     $this->storage->setSessionData($this->data);
 }
 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;
 }
Beispiel #4
0
 public function savePost()
 {
     $post = new Post();
     $form = $this->getFormFactory()->create(PostType::class, $post);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $this->em->persist($post);
         $this->em->flush();
         $this->flash->add('notice', 'form saved');
     }
     return false;
 }
 public function it_accepts_a_limit(ActionFactory $actionFactory, AbstractAction $indexAction, Request $request, ConfigurationInterface $configuration, ActionEventManager $eventManager, FlashBag $flashBag)
 {
     $actionFactory->getAction('entity', 'index')->willReturn($indexAction);
     $indexAction->getRoute()->willReturn('index_route');
     $indexAction->getRouteParameters(null)->willReturn([]);
     $this->initializeEventManager($eventManager);
     $configuration->getActionOptions('quick_export')->willReturn(['limit' => 2]);
     $this->setConfiguration($configuration);
     $response = $this->execute($request);
     $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\RedirectResponse');
     $response->getTargetUrl()->shouldReturn('index_route?');
     $flashBag->add('error', '<pim_custom_entity.export.limit_exceeded>%limit%=2;')->shouldBeCalled();
 }
 public function onResettingResetInitialize(UserEvent $event)
 {
     $token = $event->getUser()->getConfirmationToken();
     $user = $event->getManager()->findUserByConfirmationToken($token);
     if (is_null($user)) {
         $this->flashBag->add(FlashBagEvents::MESSAGE_TYPE_ERROR, $this->translator->trans('security.resetting.reset.errors.invalid_token'));
         $event->setHasError(true);
     } elseif (!$user->isPasswordRequestNonExpired($this->tokenTll)) {
         $this->flashBag->add(FlashBagEvents::MESSAGE_TYPE_ERROR, $this->translator->trans('security.resetting.reset.errors.expired_token'));
         $event->setHasError(true);
     } else {
         $user->setSalt($event->getUser()->getSalt());
         $event->setUser($user);
     }
 }
Beispiel #7
0
 public function onPostSubmit(FormEvent $event)
 {
     exit('onPostSubmitgit ');
     $data = $event->getData();
     $form = $event->getForm();
     if (!$data) {
         return;
     }
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $this->em->persist($data);
         $this->em->flush();
         $this->flash->add('notice', 'form saved');
     }
     return false;
 }
Beispiel #8
0
 public function playerByBzidAction(Player $me, Request $request, FlashBag $flashBag, $bzid = null)
 {
     if (!$me->hasPermission(Permission::VIEW_VISITOR_LOG)) {
         throw new ForbiddenException();
     }
     if ($bzid === null) {
         if (!$request->query->has('bzid')) {
             throw new BadRequestException("Please provide the BZID to search for");
         }
         $bzid = $request->query->get('bzid');
     }
     $player = Player::getFromBZID($bzid);
     if (!$player->isValid()) {
         $flashBag->add('error', "Player with BZID {$bzid} not found");
         return $this->goBack();
     }
     return new RedirectResponse($player->getURL());
 }
Beispiel #9
0
 public function testGetStorageKey()
 {
     $this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
     $attributeBag = new FlashBag('test');
     $this->assertEquals('test', $attributeBag->getStorageKey());
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     // First, check if it's an Azure User
     if (get_class($response->getResourceOwner()) != "HWI\\Bundle\\OAuthBundle\\OAuth\\ResourceOwner\\AzureResourceOwner") {
         throw new UnsupportedUserException("Can not load a user by " . get_class($response->getResourceOwner()) . ".");
     }
     // Check if this user exists
     $user = $this->userManager->findUserByEmail($response->getEmail());
     // Load groups ids
     $groups = $this->entityManager->createQueryBuilder()->select("azureRole.azureGid")->from("BdEMainBundle:AzureRole", 'azureRole')->getQuery()->getArrayResult();
     $request = ['groupIds' => []];
     foreach ($groups as $group) {
         $request['groupIds'][] = $group['azureGid'];
     }
     // Load groups for this user
     $client = new Curl();
     $client->setTimeout(20000);
     $client = new Browser($client);
     $uid = $response->getResponse()['oid'];
     $uri = "https://graph.windows.net" . "/" . $this->tenant . "/me/checkMemberGroups?api-version=1.6";
     $r = $client->post($uri, array("Authorization: Bearer " . $response->getAccessToken() . "", "Content-Type: application/json", "Accept: application/json"), json_encode($request));
     $r = json_decode($r->getContent());
     $groups = $r->value;
     $roleRepo = $this->entityManager->getRepository("BdEMainBundle:AzureRole");
     /** @var AzureRole[] $azureRoles */
     $azureRoles = $roleRepo->createQueryBuilder('azureRole')->where('azureRole.azureGid IN (?1)')->setParameter(1, $groups)->getQuery()->getResult();
     /** @var Role[] $roles */
     $roles = array();
     foreach ($azureRoles as $azureRole) {
         $roles = array_merge($roles, $azureRole->getRoles());
     }
     $roles = array_unique($roles);
     if (sizeof($roles) == 0) {
         // Try to get if it's a SuperAdmin
         $uri = "https://graph.windows.net" . "/" . $this->tenant . "/me/memberOf?api-version=1.6";
         $r = $client->get($uri, array("authorization: Bearer " . $response->getAccessToken()));
         $userRoles = json_decode($r->getContent());
         if (!property_exists($userRoles, 'value')) {
             throw new UsernameNotFoundException(sprintf("Impossible to log you !", $response->getRealName()));
         }
         $userRoles = $userRoles->value;
         foreach ($userRoles as $userRole) {
             if ($userRole->objectType == 'Role') {
                 if ($userRole->displayName == "Company Administrator" && strpos($response->getEmail(), $this->tenant) !== false) {
                     // We found an Admin !
                     $roles[] = new Role("ROLE_SUPER_ADMIN");
                     break;
                 }
             }
         }
         if (count($roles) == 0) {
             $this->flashBag->add("error", $response->getEmail() . " ne peut pas se connecter à cette application");
             throw new UsernameNotFoundException(sprintf("User '%s' has no power here!", $response->getRealName()));
         }
     }
     /** @var User $user */
     if ($user == null) {
         $user = $this->userManager->createUser();
     }
     $user->setRoles($roles);
     $user->setEmail($response->getEmail());
     $user->setEmailCanonical($response->getEmail());
     $user->setEnabled(true);
     $user->setUsername($response->getEmail());
     $user->setPlainPassword($response->getAccessToken());
     $user->setAzureAccessToken($response->getAccessToken());
     $user->setAzureRenewAccessToken($response->getRefreshToken());
     $this->userManager->updateUser($user);
     return $user;
 }
Beispiel #11
0
 /**
  * Constructor.
  *
  * @param string $name
  * @param string $storageKey
  */
 public function __construct($name = 'messages', $storageKey = '_pk_messages')
 {
     parent::__construct($storageKey);
     $this->setName($name);
 }
 /**
  * @param $isInFlash
  * @return FlashBag
  */
 private function provideFlashBag($isInFlash)
 {
     $flashBag = new FlashBag();
     if ($isInFlash) {
         $flashBag->add('all', 'flash');
     }
     return $flashBag;
 }
Beispiel #13
0
 /**
  * @param string $type
  * @param string $message
  * @param array  $translationParameters
  */
 public function addStatic($type, $message, array $translationParameters = [])
 {
     parent::add($type, $this->parseMessage($message, false, $translationParameters));
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  *
  * @param array $messages
  */
 public function setAll(array $messages)
 {
     parent::setAll($messages);
     $this->setDirty();
 }