· 6 years ago · Dec 13, 2018, 02:24 PM
1namespace AppBundleController;
2
3use AppBundleEntityApiUsers;
4use FOSRestBundleControllerAnnotations as Rest;
5use FOSRestBundleControllerFOSRestController;
6 use SymfonyComponentHttpFoundationRequest;
7use SymfonyComponentHttpFoundationResponse;
8use FOSRestBundleViewView;
9use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
10
11class 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
38security:
39
40 encoders:
41 FOSUserBundleModelUserInterface: bcrypt
42
43# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
44providers:
45 in_memory:
46 memory: ~
47
48 fos_userbundle:
49 id: fos_user.user_provider.username
50
51firewalls:
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
76access_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,
97prefer_extension: false }
98 param_fetcher_listener: true
99 view:
100 view_response_listener: 'force'
101 formats:
102 json: true
103
104fos_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
114fos_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
127username poxos22
128password 123456
129client_id 12_5wzjwogvfa80sww4wo0840wocsoo0gk08cgos0skco48k4g12e
130client_secret 2valk06xew8w4gkcswwgkg40cs8kgkkg0ssc4g4k4cgokgsdsc
131grant_type password