Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundleController;
- use NoxlogicRateLimitBundleAnnotationRateLimit;
- use SensioBundleFrameworkExtraBundleConfigurationRoute;
- use SymfonyBundleFrameworkBundleControllerController;
- use SymfonyComponentHttpFoundationRequest;
- use SymfonyComponentHttpFoundationResponse;
- class DefaultController extends Controller
- {
- /**
- * @Route("/", name="homepage")
- * @RateLimit(methods={"GET","POST"}, limit=1000, period=3600)
- */
- public function indexAction(Request $request)
- {
- // replace this example code with whatever you need
- return $this->render('default/index.html.twig');
- }
- }
- <?php
- // src/AppBundle/Entity/User.php
- namespace AppBundleEntity;
- use FOSUserBundleModelUser as BaseUser;
- use DoctrineORMMapping as ORM;
- /**
- * @ORMEntity
- * @ORMTable(name="fos_users")
- */
- class User extends BaseUser
- {
- /**
- * @ORMId
- * @ORMColumn(type="integer")
- * @ORMGeneratedValue(strategy="AUTO")
- */
- protected $id;
- public function __construct()
- {
- parent::__construct();
- // your own logic
- }
- }
- parameters:
- vendor_security.authentication_handler: AppBundleHandlerAuthenticationHandler
- services:
- authentication_handler:
- class: "%vendor_security.authentication_handler%"
- arguments: ["@router"]
- tags:
- - { name: 'monolog.logger', channel: 'security' }
- imports:
- - { resource: parameters.yml }
- - { resource: security.yml }
- - { resource: services.yml }
- # Put parameters here that don't need to change on each machine where the app is deployed
- # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
- parameters:
- locale: en
- framework:
- #esi: ~
- #translator: { fallbacks: ["%locale%"] }
- secret: "%secret%"
- router:
- resource: "%kernel.root_dir%/config/routing.yml"
- strict_requirements: ~
- form: ~
- csrf_protection: ~
- validation: { enable_annotations: true }
- #serializer: { enable_annotations: true }
- templating:
- engines: ['twig']
- default_locale: "%locale%"
- trusted_hosts: ~
- trusted_proxies: ~
- session:
- # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
- handler_id: session.handler.native_file
- save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
- fragments: ~
- http_method_override: true
- assets: ~
- php_errors:
- log: true
- # Twig Configuration
- twig:
- debug: "%kernel.debug%"
- strict_variables: "%kernel.debug%"
- # Doctrine Configuration
- doctrine:
- dbal:
- driver: pdo_mysql
- host: "%database_host%"
- port: "%database_port%"
- dbname: "%database_name%"
- user: "%database_user%"
- password: "%database_password%"
- charset: UTF8
- # if using pdo_sqlite as your database driver:
- # 1. add the path in parameters.yml
- # e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
- # 2. Uncomment database_path in parameters.yml.dist
- # 3. Uncomment next line:
- #path: "%database_path%"
- orm:
- auto_generate_proxy_classes: "%kernel.debug%"
- naming_strategy: doctrine.orm.naming_strategy.underscore
- auto_mapping: true
- doctrine_cache:
- aliases:
- apc_cache: my_apc_cache
- providers:
- my_apc_cache:
- type: apc
- namespace: my_apc_cache_ns
- aliases:
- - apc_cache
- # Swiftmailer Configuration
- swiftmailer:
- transport: "%mailer_transport%"
- username: "%mailer_user%"
- password: "%mailer_password%"
- spool: { type: memory }
- # FOSUser Configuration
- fos_user:
- db_driver: orm # other valid values are 'mongodb' and 'couchdb'
- firewall_name: main
- user_class: AppBundleEntityUser
- from_email:
- address: "%mailer_user%"
- sender_name: "%mailer_user%"
- # RateLimit Configuration
- noxlogic_rate_limit:
- enabled: true
- # The storage engine where all the rates will be stored
- storage_engine: doctrine # One of "redis"; "memcache"; "doctrine"
- # The Doctrine Cache provider to use for the doctrine storage engine
- doctrine_provider: my_apc_cache # Example: my_apc_cache
- # The HTTP status code to return when a client hits the rate limit
- rate_response_code: 429
- # The HTTP message to return when a client hits the rate limit
- rate_response_message: 'You exceeded the rate limit'
- # Should the ratelimit headers be automatically added to the response?
- display_headers: true
- # What are the different header names to add
- headers:
- limit: X-RateLimit-Limit
- remaining: X-RateLimit-Remaining
- reset: X-RateLimit-Reset
- security:
- encoders:
- FOSUserBundleModelUserInterface: bcrypt
- role_hierarchy:
- ROLE_ADMIN: ROLE_USER
- ROLE_SUPER_ADMIN: ROLE_ADMIN
- providers:
- fos_userbundle:
- id: fos_user.user_provider.username
- firewalls:
- main:
- pattern: ^/
- form_login:
- provider: fos_userbundle
- csrf_token_generator: security.csrf.token_manager
- # if you are using Symfony < 2.8, use the following config instead:
- # csrf_provider: form.csrf_provider
- logout: true
- anonymous: true
- access_control:
- - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/admin/, role: ROLE_ADMIN }
- **security.yml**
- app:
- resource: "@AppBundle/Controller/"
- type: annotation
- fos_user:
- resource: "@FOSUserBundle/Resources/config/routing/all.xml"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement