Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundleController;
  4. use NoxlogicRateLimitBundleAnnotationRateLimit;
  5. use SensioBundleFrameworkExtraBundleConfigurationRoute;
  6. use SymfonyBundleFrameworkBundleControllerController;
  7. use SymfonyComponentHttpFoundationRequest;
  8. use SymfonyComponentHttpFoundationResponse;
  9.  
  10. class DefaultController extends Controller
  11. {
  12.  
  13. /**
  14. * @Route("/", name="homepage")
  15. * @RateLimit(methods={"GET","POST"}, limit=1000, period=3600)
  16. */
  17. public function indexAction(Request $request)
  18. {
  19. // replace this example code with whatever you need
  20. return $this->render('default/index.html.twig');
  21. }
  22. }
  23.  
  24. <?php
  25. // src/AppBundle/Entity/User.php
  26.  
  27. namespace AppBundleEntity;
  28.  
  29. use FOSUserBundleModelUser as BaseUser;
  30. use DoctrineORMMapping as ORM;
  31.  
  32. /**
  33. * @ORMEntity
  34. * @ORMTable(name="fos_users")
  35. */
  36. class User extends BaseUser
  37. {
  38. /**
  39. * @ORMId
  40. * @ORMColumn(type="integer")
  41. * @ORMGeneratedValue(strategy="AUTO")
  42. */
  43. protected $id;
  44.  
  45. public function __construct()
  46. {
  47. parent::__construct();
  48. // your own logic
  49. }
  50. }
  51.  
  52. parameters:
  53. vendor_security.authentication_handler: AppBundleHandlerAuthenticationHandler
  54.  
  55. services:
  56. authentication_handler:
  57. class: "%vendor_security.authentication_handler%"
  58. arguments: ["@router"]
  59. tags:
  60. - { name: 'monolog.logger', channel: 'security' }
  61.  
  62. imports:
  63. - { resource: parameters.yml }
  64. - { resource: security.yml }
  65. - { resource: services.yml }
  66.  
  67. # Put parameters here that don't need to change on each machine where the app is deployed
  68. # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
  69. parameters:
  70. locale: en
  71.  
  72. framework:
  73. #esi: ~
  74. #translator: { fallbacks: ["%locale%"] }
  75. secret: "%secret%"
  76. router:
  77. resource: "%kernel.root_dir%/config/routing.yml"
  78. strict_requirements: ~
  79. form: ~
  80. csrf_protection: ~
  81. validation: { enable_annotations: true }
  82. #serializer: { enable_annotations: true }
  83. templating:
  84. engines: ['twig']
  85. default_locale: "%locale%"
  86. trusted_hosts: ~
  87. trusted_proxies: ~
  88. session:
  89. # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
  90. handler_id: session.handler.native_file
  91. save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
  92. fragments: ~
  93. http_method_override: true
  94. assets: ~
  95. php_errors:
  96. log: true
  97.  
  98. # Twig Configuration
  99. twig:
  100. debug: "%kernel.debug%"
  101. strict_variables: "%kernel.debug%"
  102.  
  103. # Doctrine Configuration
  104. doctrine:
  105. dbal:
  106. driver: pdo_mysql
  107. host: "%database_host%"
  108. port: "%database_port%"
  109. dbname: "%database_name%"
  110. user: "%database_user%"
  111. password: "%database_password%"
  112. charset: UTF8
  113. # if using pdo_sqlite as your database driver:
  114. # 1. add the path in parameters.yml
  115. # e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
  116. # 2. Uncomment database_path in parameters.yml.dist
  117. # 3. Uncomment next line:
  118. #path: "%database_path%"
  119.  
  120. orm:
  121. auto_generate_proxy_classes: "%kernel.debug%"
  122. naming_strategy: doctrine.orm.naming_strategy.underscore
  123. auto_mapping: true
  124.  
  125. doctrine_cache:
  126. aliases:
  127. apc_cache: my_apc_cache
  128.  
  129. providers:
  130. my_apc_cache:
  131. type: apc
  132. namespace: my_apc_cache_ns
  133. aliases:
  134. - apc_cache
  135.  
  136. # Swiftmailer Configuration
  137. swiftmailer:
  138. transport: "%mailer_transport%"
  139. username: "%mailer_user%"
  140. password: "%mailer_password%"
  141. spool: { type: memory }
  142.  
  143. # FOSUser Configuration
  144. fos_user:
  145. db_driver: orm # other valid values are 'mongodb' and 'couchdb'
  146. firewall_name: main
  147. user_class: AppBundleEntityUser
  148. from_email:
  149. address: "%mailer_user%"
  150. sender_name: "%mailer_user%"
  151.  
  152. # RateLimit Configuration
  153. noxlogic_rate_limit:
  154. enabled: true
  155.  
  156. # The storage engine where all the rates will be stored
  157. storage_engine: doctrine # One of "redis"; "memcache"; "doctrine"
  158.  
  159. # The Doctrine Cache provider to use for the doctrine storage engine
  160. doctrine_provider: my_apc_cache # Example: my_apc_cache
  161.  
  162. # The HTTP status code to return when a client hits the rate limit
  163. rate_response_code: 429
  164.  
  165. # The HTTP message to return when a client hits the rate limit
  166. rate_response_message: 'You exceeded the rate limit'
  167.  
  168. # Should the ratelimit headers be automatically added to the response?
  169. display_headers: true
  170.  
  171. # What are the different header names to add
  172. headers:
  173. limit: X-RateLimit-Limit
  174. remaining: X-RateLimit-Remaining
  175. reset: X-RateLimit-Reset
  176.  
  177. security:
  178. encoders:
  179. FOSUserBundleModelUserInterface: bcrypt
  180.  
  181. role_hierarchy:
  182. ROLE_ADMIN: ROLE_USER
  183. ROLE_SUPER_ADMIN: ROLE_ADMIN
  184.  
  185. providers:
  186. fos_userbundle:
  187. id: fos_user.user_provider.username
  188.  
  189. firewalls:
  190. main:
  191. pattern: ^/
  192. form_login:
  193. provider: fos_userbundle
  194. csrf_token_generator: security.csrf.token_manager
  195. # if you are using Symfony < 2.8, use the following config instead:
  196. # csrf_provider: form.csrf_provider
  197.  
  198. logout: true
  199. anonymous: true
  200.  
  201. access_control:
  202. - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  203. - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
  204. - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
  205. - { path: ^/admin/, role: ROLE_ADMIN }
  206. **security.yml**
  207.  
  208. app:
  209. resource: "@AppBundle/Controller/"
  210. type: annotation
  211. fos_user:
  212. resource: "@FOSUserBundle/Resources/config/routing/all.xml"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement