Guest User

Untitled

a guest
Dec 13th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. namespace AppBundleController;
  2.  
  3. use AppBundleEntityApiUsers;
  4. use FOSRestBundleControllerAnnotations as Rest;
  5. use FOSRestBundleControllerFOSRestController;
  6. use SymfonyComponentHttpFoundationRequest;
  7. use SymfonyComponentHttpFoundationResponse;
  8. use FOSRestBundleViewView;
  9. use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
  10.  
  11. class ApiController extends FOSRestController
  12. {
  13. /**
  14. * @RestPost("regUser/")
  15. */
  16. public function addPostAction(Request $request,
  17. UserPasswordEncoderInterface $encoder)
  18. {
  19. $data = new ApiUsers();
  20.  
  21. $username = $request->get('username');
  22. $email = $request->get('email');
  23. $password = $request->get('password');
  24.  
  25. if(empty($username) || empty($password))
  26. {
  27. return new View("NULL VALUES ARE NOT ALLOWED", Response::HTTP_NOT_ACCEPTABLE);
  28. }
  29. $data->setUsername($username);
  30. $data->setPassword($password);
  31. $data->setEmail($email);
  32. $em = $this->getDoctrine()->getManager();
  33. $em->persist($data);
  34. $em->flush();
  35. return new View("User Added Successfully", Response::HTTP_OK);
  36. }
  37.  
  38. security:
  39.  
  40. encoders:
  41. FOSUserBundleModelUserInterface: bcrypt
  42.  
  43. # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
  44. providers:
  45. in_memory:
  46. memory: ~
  47.  
  48. fos_userbundle:
  49. id: fos_user.user_provider.username
  50.  
  51. firewalls:
  52. # disables authentication for assets and the profiler, adapt it according to your needs
  53. dev:
  54. pattern: ^/(_(profiler|wdt)|css|images|js)/
  55. security: false
  56.  
  57. oauth_token: # Everyone can access the access token URL.
  58. pattern: ^/oauth/v2/token
  59. security: false
  60.  
  61. api:
  62. pattern: ^/api # All URLs are protected
  63. fos_oauth: true # OAuth2 protected resource
  64. stateless: true # Do no set session cookies
  65. anonymous: false # An
  66. main:
  67. anonymous: ~
  68. # activate different ways to authenticate
  69.  
  70. # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
  71. #http_basic: ~
  72.  
  73. # https://symfony.com/doc/current/security/form_login_setup.html
  74. #form_login: ~
  75.  
  76. access_control:
  77. - { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }
  78.  
  79. # Nelmio CORS Configuration
  80. nelmio_cors:
  81. defaults:
  82. allow_credentials: false
  83. allow_origin: ['*']
  84. allow_headers: ['*']
  85. allow_methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']
  86. max_age: 3600
  87. hosts: []
  88. origin_regex: false
  89.  
  90.  
  91. # FOSRest Configuration
  92. fos_rest:
  93. body_listener: true
  94. format_listener:
  95. rules:
  96. - { path: '^/', priorities: ['json'], fallback_format: json,
  97. prefer_extension: false }
  98. param_fetcher_listener: true
  99. view:
  100. view_response_listener: 'force'
  101. formats:
  102. json: true
  103.  
  104. fos_user:
  105. db_driver: orm # other valid values are 'mongodb' and 'couchdb'
  106. firewall_name: main
  107. user_class: AppBundleEntityApiUsers
  108. service: # this lines
  109. mailer: fos_user.mailer.twig_swift # this lines
  110. from_email:
  111. address: "xsx"
  112. sender_name: "sxs"
  113.  
  114. fos_oauth_server:
  115. db_driver: orm
  116. client_class: AppBundleEntityOauth2Clients
  117. access_token_class: AppBundleEntityOauth2AccessTokens
  118. refresh_token_class: AppBundleEntityOauth2RefreshTokens
  119. auth_code_class: AppBundleEntityOauth2AuthCodes
  120. service:
  121. user_provider: fos_user.user_provider.username
  122. options:
  123. access_token_lifetime: 86400
  124. refresh_token_lifetime: 1209600
  125. auth_code_lifetime: 30
  126.  
  127. username poxos22
  128. password 123456
  129. client_id 12_5wzjwogvfa80sww4wo0840wocsoo0gk08cgos0skco48k4g12e
  130. client_secret 2valk06xew8w4gkcswwgkg40cs8kgkkg0ssc4g4k4cgokgsdsc
  131. grant_type password
Add Comment
Please, Sign In to add comment