Skip to content

Commit

Permalink
rate limiting per user
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisTrezzini committed Apr 3, 2019
1 parent b72dc3c commit 9897da2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion back/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,6 @@ services:
tags:
- { name: form.type, alias: user }

BOMO\IcalBundle\Provider\IcsProvider: '@bomo_ical.ics_provider'
App\Listener\RateLimitGenerateKeyListener:
tags:
- { name: kernel.event_listener, event: ratelimit.generate.key, method: onGenerateKey }
29 changes: 29 additions & 0 deletions back/src/Listener/RateLimitGenerateKeyListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Listener;

use Noxlogic\RateLimitBundle\Events\GenerateKeyEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class RateLimitGenerateKeyListener
{
protected $tokenStorage;

/**
* @param $tokenStorage
*/
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

/**
* @param GenerateKeyEvent $event
*/
public function onGenerateKey(GenerateKeyEvent $event)
{
$token = $this->tokenStorage->getToken();

$event->addToKey($token->getUsername());
}
}

0 comments on commit 9897da2

Please sign in to comment.