Send unprocessed notifications to logged User and device
- Logged User (toUser)
- DeviceID (toDevice)

@param Request $request
546440
public function sendUnprocessNotification(Request $request) {
        // Get toUser
        /** @var LoginHelper $loginHelper */
        $loginHelper = $this->container->get('sopinet_login_helper');
        /** @var $user */
        try {
            $user = $loginHelper->getUser($request);
        } catch(Exception $e) {
            throw new Exception('User is required');
        }

        /** @var EntityManager $em */
        $em = $this->container->get('doctrine.orm.default_entity_manager');

        // Get toDevice
        $reDevice = $em->getRepository("SopinetChatBundle:Device");
        /** @var Device $device */
        $device = $reDevice->findOneByDeviceId($request->get('deviceId'));
        if ($device == null) throw new Exception('Device is not valid');
        $isDevice = false;
        /** @var Device $dev */
        foreach($user->getDevices() as $dev) {
            if ($dev->getDeviceId() == $device->getDeviceId()) $isDevice = true;
        }
        if (!$isDevice) throw new Exception('Device is not valid');

        // Get MessagePackage
        $reMessagePackage = $em->getRepository("SopinetChatBundle:MessagePackage");
        $messagesPackage = $reMessagePackage->findBy(array(
            'toUser' => $user->getId(),
            'toDevice' => $device->getDeviceId(),
            'processed' => false
        ));

        /** @var MessageHelper $messageHelper */
        $messageHelper = $this->container->get('sopinet_chatbundle_messagehelper');

        $i = 0;
        /** @var MessagePackage $messagePackage */
        foreach($messagesPackage as $messagePackage) {
            $isOk = $messageHelper->sendRealMessageToDevice(
                $messagePackage->getMessage(),
                $messagePackage->getToDevice(),
                $messagePackage->getToUser()
            );
            if ($isOk) $i++;
        }

        return $i;
    }
161334
public function messagesSendAction(Request $request)
    {
        $query = $request->request->all();
        $messages = $this->om->findList('Claroline\PlannedNotificationBundle\Entity\Message', 'uuid', $query['messages']);
        $users = $this->om->findList('Claroline\CoreBundle\Entity\User', 'uuid', $query['users']);
        $this->manager->sendMessages($messages, $users);

        return new JsonResponse('success', 200);
    }
64838
public function notifyAction(Request $request)
    {
        /** @var Event $content */
        $content = json_decode($request->getContent(), true);

        // Get the Event again from Stripe for security reasons
        $stripeWebhookEvent = $this->get('stripe_bundle.manager.stripe_api')->retrieveEvent($content['id']);

        // Now check the event doesn't already exist in the database
        $localWebhookEvent = $this->get('stripe_bundle.entity_manager')->getRepository('SHQStripeBundle:StripeLocalWebhookEvent')->findOneByStripeId($stripeWebhookEvent->id);

        if (false !== strpos($content['type'], 'deleted')) {
            $objectType = ucfirst($content['data']['object']['object']);
            if (null === $localWebhookEvent) {
                $localResource = $this->get('stripe_bundle.entity_manager')
                    ->getRepository('SHQStripeBundle:StripeLocal' . $objectType)
                    ->findOneBy(['id' => $content['data']['object']['id']]);
            }
            $syncer = $this->get('stripe_bundle.syncer.' . $objectType);
            if (method_exists($syncer, 'removeLocal')) {
                $this->get('stripe_bundle.syncer.' . $objectType)->removeLocal($localResource, $stripeWebhookEvent);
            }

            return new Response('ok', 200);
        }

        if (null === $localWebhookEvent) {
            // Create the entity object (this will be persisted)
            $localWebhookEvent = new StripeLocalWebhookEvent();

            // Now sync the entity LocalWebhookEvent with the remote Stripe\Event (persisting is automatically handled)
            $this->get('stripe_bundle.syncer.webhook_event')->syncLocalFromStripe($localWebhookEvent, $stripeWebhookEvent);
        }

        // Guess the event to dispatch to the application
        $guessedDispatchingEvent = $this->get('stripe_bundle.guesser.event_guesser')->guess($stripeWebhookEvent, $localWebhookEvent);

        $this->container->get('event_dispatcher')->dispatch($guessedDispatchingEvent['type'], $guessedDispatchingEvent['object']);

        return new Response('ok', 200);
    }
1081395
public function setRequest(Request $request)
    {
        $this->request = $request;

        $this->cachedRoot = null;
        $this->cachedScheme = null;
        $this->routeGenerator = null;
    }
312026
private function applySecurity($context, $privacy, Request $request)
    {
        if (mb_strtoupper($privacy) === 'PUBLIC') {
            return;
        }

        $security = $this->securityContext->getSecurity($context);

        if (! $security->getUser(true)) {
            throw Unauthenticated::guest($security)->inContext($context);
        }

        // Try to make the route, and let it explode upwards
        try {
            $route = $request->route();

            if ($route instanceof Route) {
                $route = $route->uri();
            }

            if ($route) {
                $security->url()->to($route);
            }
        } catch (Unauthorized $e) {
            throw $e->inContext($context);
        }
    }
586830
public function readNotifications(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            $this->app->abort(400);
        }

        try {
            $this->getEventsManager()->read(
                explode('_', (string) $request->request->get('notifications')),
                $this->getAuthenticatedUser()->getId()
            );

            return $this->app->json(['success' => true, 'message' => '']);
        } catch (\Exception $e) {
            return $this->app->json(['success' => false, 'message' => $e->getMessage()]);
        }
    }
471771
public function deleteUsersAction(Request $request)
    {
        $format = $request->get('_format', 'json');

        $facade = $this->get('jms_serializer')->deserialize(
            $request->getContent(),
            $this->getParameter('open_orchestra_user_admin.facade.user_collection.class'),
            $format
        );
        $userRepository = $this->get('open_orchestra_user.repository.user');
        $users = $this->get('open_orchestra_api.transformer_manager')->reverseTransform('user_collection', $facade);
        $userIds = array();
        foreach ($users as $user) {
            if ($this->isGranted(ContributionActionInterface::DELETE, $user)) {
                $userIds[] = $user->getId();
                $this->dispatchEvent(UserEvents::USER_DELETE, new UserEvent($user));
            }
        }
        $userRepository->removeUsers($userIds);

        return array();
    }
358354
protected function bindIdIfProvided(JsonRpcRequest $request, array $item) : void
    {
        /** If no id defined => request is a notification */
        if (isset($item[self::KEY_ID])) {
            $request->setId(
                $item[self::KEY_ID] == (string)((int)$item[self::KEY_ID])
                    ? (int)$item[self::KEY_ID] // Convert it in case it's a string containing an int
                    : (string)$item[self::KEY_ID] // Convert to string in all other cases
            );
        }
    }
718326
public function validateAndParseWebhookNotificationFromRequest(\Symfony\Component\HttpFoundation\Request $request) {
        $json_data = json_decode($request->getContent(), true);
        if (!is_array($json_data)) { throw new AuthorizationException("Invalid webhook data received"); }

        // make sure the message is signed properly
        //   throws an exception if invalid
        $this->validateWebhookNotification($json_data);

        return $this->parseWebhookNotificationData($json_data);
    }
247970
public function update(Request $request)
    {
        if ($request->has('notification')) {
            foreach ($request->notification as $id => $severity) {
                if (in_array(strtolower($severity), ['low', 'medium', 'high', 'disabled'])) {
                    Severity::where('id', $id)->update(['severity' => strtolower($severity)]);
                }
            }
        }

        return redirect(route('eyewitness.settings.index').'#severity')->withSuccess('The notification severity settings have been updated.');
    }
904422
public function beforeSend($request)
    {
        $event = new RequestEvent();
        $event->request = $request;
        $this->trigger(self::EVENT_BEFORE_SEND, $event);
    }
676590
public function index(Request $request)
    {
        $notifications = $this->service->userBasedPaginated(Auth::id());
        return view('notifications.index')->with('notifications', $notifications);
    }
100436
public function read($id, ReadNotificationRequest $request)
    {
        $user = $request->user();
        $item = $user->notifications()->find($id);
        if (empty($item)) {
            return $this->sendError('Notification not found');
        }
        $item->markAsRead();

        return $this->sendResponse($item, '');
    }
1224193
public function postRequest(Request $request)
    {
        // Validate the form data
        $result = $this->validate($request, [
            'email' => 'required|email|max:255'
        ]);

        // Fetch the user in question
        $user = Sentinel::findUserByCredentials(['email' => $request->get('email')]);

        // Only send them an email if they have a valid, inactive account
        if ($user) {
            // Generate a new code
            $reminder = Reminder::create($user);

            // Send the email
            $code = $reminder->code;
            $email = $user->email;
            Mail::to($email)->queue(new CentaurPasswordReset($code));
        }

        $message = 'Instructions for changing your password will be sent to your email address if it is associated with a valid account.';

        if ($request->expectsJson()) {
            return response()->json(['message' => $message, 'code' => $code], 200);
        }

        Session::flash('success', $message);
        return redirect()->route('dashboard');
    }
1099082
protected function clearLoginAttempts(Request $request)
    {
        $rateLimiter = App::make('Nova\Cache\RateLimiter');

        $rateLimiter->clear($this->getThrottleKey($request));
    }
135814
public function runBeforeSendingCallbacks(Request $request): Request
    {
        return tap($request, function ($request) {
            $this->beforeSendingCallbacks->each->__invoke(new HttpRequest($request));
        });
    }
861655
public function checkEmailAction(Request $request)
    {
        $email = $request->query->get('email');

        if (empty($email)) {
            // the user does not come from the sendEmail action
            return new RedirectResponse($this->generateUrl('fos_user_resetting_request'));
        }

        return $this->render('FOSUserBundle:Resetting:checkEmail.html.twig', array(
            'email' => $email,
        ));
    }