@@ -9,40 +9,40 @@ |
||
9 | 9 | |
10 | 10 | class GroupsController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * The validations rules used by the base api controller |
|
14 | - * to check before add. |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $validationRules = [ |
|
18 | - 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
19 | - ]; |
|
12 | + /** |
|
13 | + * The validations rules used by the base api controller |
|
14 | + * to check before add. |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $validationRules = [ |
|
18 | + 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
19 | + ]; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Init new object. |
|
23 | - * |
|
24 | - * @param GroupRepository $repo |
|
25 | - * @param CoreConfig $config |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function __construct(GroupRepository $repo, CoreConfig $config) |
|
29 | - { |
|
30 | - parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclGroup'); |
|
31 | - } |
|
21 | + /** |
|
22 | + * Init new object. |
|
23 | + * |
|
24 | + * @param GroupRepository $repo |
|
25 | + * @param CoreConfig $config |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function __construct(GroupRepository $repo, CoreConfig $config) |
|
29 | + { |
|
30 | + parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclGroup'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Handle an assign permissions to group request. |
|
35 | - * |
|
36 | - * @param \Illuminate\Http\Request $request |
|
37 | - * @return \Illuminate\Http\Response |
|
38 | - */ |
|
39 | - public function assignpermissions(Request $request) |
|
40 | - { |
|
41 | - $this->validate($request, [ |
|
42 | - 'permission_ids' => 'required|exists:permissions,id', |
|
43 | - 'group_id' => 'required|array|exists:groups,id' |
|
44 | - ]); |
|
33 | + /** |
|
34 | + * Handle an assign permissions to group request. |
|
35 | + * |
|
36 | + * @param \Illuminate\Http\Request $request |
|
37 | + * @return \Illuminate\Http\Response |
|
38 | + */ |
|
39 | + public function assignpermissions(Request $request) |
|
40 | + { |
|
41 | + $this->validate($request, [ |
|
42 | + 'permission_ids' => 'required|exists:permissions,id', |
|
43 | + 'group_id' => 'required|array|exists:groups,id' |
|
44 | + ]); |
|
45 | 45 | |
46 | - return new $this->modelResource($this->repo->assignPermissions($request->get('group_id'), $request->get('permission_ids'))); |
|
47 | - } |
|
46 | + return new $this->modelResource($this->repo->assignPermissions($request->get('group_id'), $request->get('permission_ids'))); |
|
47 | + } |
|
48 | 48 | } |
@@ -8,15 +8,15 @@ |
||
8 | 8 | |
9 | 9 | class PermissionsController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * Init new object. |
|
13 | - * |
|
14 | - * @param PermissionRepository $repo |
|
15 | - * @param CoreConfig $config |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function __construct(PermissionRepository $repo, CoreConfig $config) |
|
19 | - { |
|
20 | - parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclPermission'); |
|
21 | - } |
|
11 | + /** |
|
12 | + * Init new object. |
|
13 | + * |
|
14 | + * @param PermissionRepository $repo |
|
15 | + * @param CoreConfig $config |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function __construct(PermissionRepository $repo, CoreConfig $config) |
|
19 | + { |
|
20 | + parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclPermission'); |
|
21 | + } |
|
22 | 22 | } |
@@ -11,285 +11,285 @@ |
||
11 | 11 | |
12 | 12 | class UsersController extends BaseApiController |
13 | 13 | { |
14 | - /** |
|
15 | - * List of all route actions that the base api controller |
|
16 | - * will skip permissions check for them. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
20 | - |
|
21 | - /** |
|
22 | - * List of all route actions that the base api controller |
|
23 | - * will skip login check for them. |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
27 | - |
|
28 | - /** |
|
29 | - * The validations rules used by the base api controller |
|
30 | - * to check before add. |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $validationRules = [ |
|
34 | - 'name' => 'nullable|string', |
|
35 | - 'email' => 'required|email|unique:users,email,{id}', |
|
36 | - 'password' => 'nullable|min:6' |
|
37 | - ]; |
|
38 | - |
|
39 | - /** |
|
40 | - * The loginProxy implementation. |
|
41 | - * |
|
42 | - * @var \App\Modules\Acl\Proxy\LoginProxy |
|
43 | - */ |
|
44 | - protected $loginProxy; |
|
45 | - |
|
46 | - /** |
|
47 | - * Init new object. |
|
48 | - * |
|
49 | - * @param LoginProxy $loginProxy |
|
50 | - * @param UserRepository $repo |
|
51 | - * @param CoreConfig $config |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function __construct(LoginProxy $loginProxy, UserRepository $repo, CoreConfig $config) |
|
55 | - { |
|
56 | - $this->loginProxy = $loginProxy; |
|
57 | - parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclUser'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Return the logged in user account. |
|
62 | - * |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function account() |
|
66 | - { |
|
67 | - return new $this->modelResource($this->repo->account($this->relations)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Block the user. |
|
72 | - * |
|
73 | - * @param integer $id Id of the user. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function block($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->block($id)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Unblock the user. |
|
83 | - * |
|
84 | - * @param integer $id Id of the user. |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function unblock($id) |
|
88 | - { |
|
89 | - return new $this->modelResource($this->repo->unblock($id)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Logout the user. |
|
94 | - * |
|
95 | - * @return \Illuminate\Http\Response |
|
96 | - */ |
|
97 | - public function logout() |
|
98 | - { |
|
99 | - return new GeneralResource($this->loginProxy->logout()); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Handle a registration request. |
|
104 | - * |
|
105 | - * @param \Illuminate\Http\Request $request |
|
106 | - * @return \Illuminate\Http\Response |
|
107 | - */ |
|
108 | - public function register(Request $request) |
|
109 | - { |
|
110 | - $this->validate($request, [ |
|
111 | - 'name' => 'nullable|string', |
|
112 | - 'email' => 'required|email|unique:users,email,{id}', |
|
113 | - 'password' => 'required|min:6' |
|
114 | - ]); |
|
115 | - |
|
116 | - return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password'))); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Handle a login request to the application. |
|
121 | - * |
|
122 | - * @param \Illuminate\Http\Request $request |
|
123 | - * @return \Illuminate\Http\Response |
|
124 | - */ |
|
125 | - public function login(Request $request) |
|
126 | - { |
|
127 | - $this->validate($request, [ |
|
128 | - 'email' => 'required|email', |
|
129 | - 'password' => 'required|min:6', |
|
130 | - 'admin' => 'nullable|boolean' |
|
131 | - ]); |
|
14 | + /** |
|
15 | + * List of all route actions that the base api controller |
|
16 | + * will skip permissions check for them. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
20 | + |
|
21 | + /** |
|
22 | + * List of all route actions that the base api controller |
|
23 | + * will skip login check for them. |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
27 | + |
|
28 | + /** |
|
29 | + * The validations rules used by the base api controller |
|
30 | + * to check before add. |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $validationRules = [ |
|
34 | + 'name' => 'nullable|string', |
|
35 | + 'email' => 'required|email|unique:users,email,{id}', |
|
36 | + 'password' => 'nullable|min:6' |
|
37 | + ]; |
|
38 | + |
|
39 | + /** |
|
40 | + * The loginProxy implementation. |
|
41 | + * |
|
42 | + * @var \App\Modules\Acl\Proxy\LoginProxy |
|
43 | + */ |
|
44 | + protected $loginProxy; |
|
45 | + |
|
46 | + /** |
|
47 | + * Init new object. |
|
48 | + * |
|
49 | + * @param LoginProxy $loginProxy |
|
50 | + * @param UserRepository $repo |
|
51 | + * @param CoreConfig $config |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function __construct(LoginProxy $loginProxy, UserRepository $repo, CoreConfig $config) |
|
55 | + { |
|
56 | + $this->loginProxy = $loginProxy; |
|
57 | + parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclUser'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Return the logged in user account. |
|
62 | + * |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function account() |
|
66 | + { |
|
67 | + return new $this->modelResource($this->repo->account($this->relations)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Block the user. |
|
72 | + * |
|
73 | + * @param integer $id Id of the user. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function block($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->block($id)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Unblock the user. |
|
83 | + * |
|
84 | + * @param integer $id Id of the user. |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function unblock($id) |
|
88 | + { |
|
89 | + return new $this->modelResource($this->repo->unblock($id)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Logout the user. |
|
94 | + * |
|
95 | + * @return \Illuminate\Http\Response |
|
96 | + */ |
|
97 | + public function logout() |
|
98 | + { |
|
99 | + return new GeneralResource($this->loginProxy->logout()); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Handle a registration request. |
|
104 | + * |
|
105 | + * @param \Illuminate\Http\Request $request |
|
106 | + * @return \Illuminate\Http\Response |
|
107 | + */ |
|
108 | + public function register(Request $request) |
|
109 | + { |
|
110 | + $this->validate($request, [ |
|
111 | + 'name' => 'nullable|string', |
|
112 | + 'email' => 'required|email|unique:users,email,{id}', |
|
113 | + 'password' => 'required|min:6' |
|
114 | + ]); |
|
115 | + |
|
116 | + return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password'))); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Handle a login request to the application. |
|
121 | + * |
|
122 | + * @param \Illuminate\Http\Request $request |
|
123 | + * @return \Illuminate\Http\Response |
|
124 | + */ |
|
125 | + public function login(Request $request) |
|
126 | + { |
|
127 | + $this->validate($request, [ |
|
128 | + 'email' => 'required|email', |
|
129 | + 'password' => 'required|min:6', |
|
130 | + 'admin' => 'nullable|boolean' |
|
131 | + ]); |
|
132 | 132 | |
133 | - $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin')); |
|
134 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Handle a social login request of the none admin to the application. |
|
139 | - * |
|
140 | - * @param \Illuminate\Http\Request $request |
|
141 | - * @return \Illuminate\Http\Response |
|
142 | - */ |
|
143 | - public function loginSocial(Request $request) |
|
144 | - { |
|
145 | - $this->validate($request, [ |
|
146 | - 'auth_code' => 'required_without:access_token', |
|
147 | - 'access_token' => 'required_without:auth_code', |
|
148 | - 'type' => 'required|in:facebook,google' |
|
149 | - ]); |
|
150 | - |
|
151 | - $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
152 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Assign the given groups to the given user. |
|
157 | - * |
|
158 | - * @param \Illuminate\Http\Request $request |
|
159 | - * @return \Illuminate\Http\Response |
|
160 | - */ |
|
161 | - public function assigngroups(Request $request) |
|
162 | - { |
|
163 | - $this->validate($request, [ |
|
164 | - 'group_ids' => 'required|exists:groups,id', |
|
165 | - 'user_id' => 'required|exists:users,id' |
|
166 | - ]); |
|
167 | - |
|
168 | - return new $this->modelResource($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids'))); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Send a reset link to the given user. |
|
173 | - * |
|
174 | - * @param \Illuminate\Http\Request $request |
|
175 | - * @return \Illuminate\Http\Response |
|
176 | - */ |
|
177 | - public function sendreset(Request $request) |
|
178 | - { |
|
179 | - $this->validate($request, ['email' => 'required|email']); |
|
180 | - |
|
181 | - return new GeneralResource($this->repo->sendReset($request->get('email'))); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Reset the given user's password. |
|
186 | - * |
|
187 | - * @param \Illuminate\Http\Request $request |
|
188 | - * @return \Illuminate\Http\Response |
|
189 | - */ |
|
190 | - public function resetpassword(Request $request) |
|
191 | - { |
|
192 | - $this->validate($request, [ |
|
193 | - 'token' => 'required', |
|
194 | - 'email' => 'required|email', |
|
195 | - 'password' => 'required|confirmed|min:6', |
|
196 | - 'password_confirmation' => 'required', |
|
197 | - ]); |
|
198 | - |
|
199 | - return new GeneralResource($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token'))); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Change the logged in user password. |
|
204 | - * |
|
205 | - * @param \Illuminate\Http\Request $request |
|
206 | - * @return \Illuminate\Http\Response |
|
207 | - */ |
|
208 | - public function changePassword(Request $request) |
|
209 | - { |
|
210 | - $this->validate($request, [ |
|
211 | - 'old_password' => 'required', |
|
212 | - 'password' => 'required|confirmed|min:6', |
|
213 | - 'password_confirmation' => 'required', |
|
214 | - ]); |
|
215 | - |
|
216 | - return new GeneralResource($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation'))); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Confirm email using the confirmation code. |
|
221 | - * |
|
222 | - * @param \Illuminate\Http\Request $request |
|
223 | - * @return \Illuminate\Http\Response |
|
224 | - */ |
|
225 | - public function confirmEmail(Request $request) |
|
226 | - { |
|
227 | - $this->validate($request, [ |
|
228 | - 'confirmation_code' => 'required|string' |
|
229 | - ]); |
|
230 | - |
|
231 | - return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code'))); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Resend the email confirmation mail. |
|
236 | - * |
|
237 | - * @param \Illuminate\Http\Request $request |
|
238 | - * @return \Illuminate\Http\Response |
|
239 | - */ |
|
240 | - public function resendEmailConfirmation(Request $request) |
|
241 | - { |
|
242 | - $this->validate($request, [ |
|
243 | - 'email' => 'required|exists:users,email' |
|
244 | - ]); |
|
245 | - |
|
246 | - return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email'))); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Refresh the expired login token. |
|
251 | - * |
|
252 | - * @param \Illuminate\Http\Request $request |
|
253 | - * @return \Illuminate\Http\Response |
|
254 | - */ |
|
255 | - public function refreshtoken(Request $request) |
|
256 | - { |
|
257 | - $this->validate($request, [ |
|
258 | - 'refreshtoken' => 'required', |
|
259 | - ]); |
|
260 | - |
|
261 | - return new GeneralResource($this->loginProxy->refreshtoken($request->get('refreshtoken'))); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Paginate all users with in the given group. |
|
266 | - * |
|
267 | - * @param \Illuminate\Http\Request $request |
|
268 | - * @param string $groupName The name of the requested group. |
|
269 | - * @param integer $perPage Number of rows per page default 15. |
|
270 | - * @param string $sortBy The name of the column to sort by. |
|
271 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
272 | - * @return \Illuminate\Http\Response |
|
273 | - */ |
|
274 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
275 | - { |
|
276 | - return $this->modelResource::collection($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc)); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Save the given data to the logged in user. |
|
281 | - * |
|
282 | - * @param \Illuminate\Http\Request $request |
|
283 | - * @return \Illuminate\Http\Response |
|
284 | - */ |
|
285 | - public function saveProfile(Request $request) |
|
286 | - { |
|
287 | - $this->validate($request, [ |
|
288 | - 'profile_picture' => 'nullable|string', |
|
289 | - 'name' => 'nullable|string', |
|
290 | - 'email' => 'required|email|unique:users,email,'.\Auth::id() |
|
291 | - ]); |
|
292 | - |
|
293 | - return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture'))); |
|
294 | - } |
|
133 | + $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin')); |
|
134 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Handle a social login request of the none admin to the application. |
|
139 | + * |
|
140 | + * @param \Illuminate\Http\Request $request |
|
141 | + * @return \Illuminate\Http\Response |
|
142 | + */ |
|
143 | + public function loginSocial(Request $request) |
|
144 | + { |
|
145 | + $this->validate($request, [ |
|
146 | + 'auth_code' => 'required_without:access_token', |
|
147 | + 'access_token' => 'required_without:auth_code', |
|
148 | + 'type' => 'required|in:facebook,google' |
|
149 | + ]); |
|
150 | + |
|
151 | + $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
152 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Assign the given groups to the given user. |
|
157 | + * |
|
158 | + * @param \Illuminate\Http\Request $request |
|
159 | + * @return \Illuminate\Http\Response |
|
160 | + */ |
|
161 | + public function assigngroups(Request $request) |
|
162 | + { |
|
163 | + $this->validate($request, [ |
|
164 | + 'group_ids' => 'required|exists:groups,id', |
|
165 | + 'user_id' => 'required|exists:users,id' |
|
166 | + ]); |
|
167 | + |
|
168 | + return new $this->modelResource($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids'))); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Send a reset link to the given user. |
|
173 | + * |
|
174 | + * @param \Illuminate\Http\Request $request |
|
175 | + * @return \Illuminate\Http\Response |
|
176 | + */ |
|
177 | + public function sendreset(Request $request) |
|
178 | + { |
|
179 | + $this->validate($request, ['email' => 'required|email']); |
|
180 | + |
|
181 | + return new GeneralResource($this->repo->sendReset($request->get('email'))); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Reset the given user's password. |
|
186 | + * |
|
187 | + * @param \Illuminate\Http\Request $request |
|
188 | + * @return \Illuminate\Http\Response |
|
189 | + */ |
|
190 | + public function resetpassword(Request $request) |
|
191 | + { |
|
192 | + $this->validate($request, [ |
|
193 | + 'token' => 'required', |
|
194 | + 'email' => 'required|email', |
|
195 | + 'password' => 'required|confirmed|min:6', |
|
196 | + 'password_confirmation' => 'required', |
|
197 | + ]); |
|
198 | + |
|
199 | + return new GeneralResource($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token'))); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Change the logged in user password. |
|
204 | + * |
|
205 | + * @param \Illuminate\Http\Request $request |
|
206 | + * @return \Illuminate\Http\Response |
|
207 | + */ |
|
208 | + public function changePassword(Request $request) |
|
209 | + { |
|
210 | + $this->validate($request, [ |
|
211 | + 'old_password' => 'required', |
|
212 | + 'password' => 'required|confirmed|min:6', |
|
213 | + 'password_confirmation' => 'required', |
|
214 | + ]); |
|
215 | + |
|
216 | + return new GeneralResource($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation'))); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Confirm email using the confirmation code. |
|
221 | + * |
|
222 | + * @param \Illuminate\Http\Request $request |
|
223 | + * @return \Illuminate\Http\Response |
|
224 | + */ |
|
225 | + public function confirmEmail(Request $request) |
|
226 | + { |
|
227 | + $this->validate($request, [ |
|
228 | + 'confirmation_code' => 'required|string' |
|
229 | + ]); |
|
230 | + |
|
231 | + return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code'))); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Resend the email confirmation mail. |
|
236 | + * |
|
237 | + * @param \Illuminate\Http\Request $request |
|
238 | + * @return \Illuminate\Http\Response |
|
239 | + */ |
|
240 | + public function resendEmailConfirmation(Request $request) |
|
241 | + { |
|
242 | + $this->validate($request, [ |
|
243 | + 'email' => 'required|exists:users,email' |
|
244 | + ]); |
|
245 | + |
|
246 | + return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email'))); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Refresh the expired login token. |
|
251 | + * |
|
252 | + * @param \Illuminate\Http\Request $request |
|
253 | + * @return \Illuminate\Http\Response |
|
254 | + */ |
|
255 | + public function refreshtoken(Request $request) |
|
256 | + { |
|
257 | + $this->validate($request, [ |
|
258 | + 'refreshtoken' => 'required', |
|
259 | + ]); |
|
260 | + |
|
261 | + return new GeneralResource($this->loginProxy->refreshtoken($request->get('refreshtoken'))); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Paginate all users with in the given group. |
|
266 | + * |
|
267 | + * @param \Illuminate\Http\Request $request |
|
268 | + * @param string $groupName The name of the requested group. |
|
269 | + * @param integer $perPage Number of rows per page default 15. |
|
270 | + * @param string $sortBy The name of the column to sort by. |
|
271 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
272 | + * @return \Illuminate\Http\Response |
|
273 | + */ |
|
274 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
275 | + { |
|
276 | + return $this->modelResource::collection($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc)); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Save the given data to the logged in user. |
|
281 | + * |
|
282 | + * @param \Illuminate\Http\Request $request |
|
283 | + * @return \Illuminate\Http\Response |
|
284 | + */ |
|
285 | + public function saveProfile(Request $request) |
|
286 | + { |
|
287 | + $this->validate($request, [ |
|
288 | + 'profile_picture' => 'nullable|string', |
|
289 | + 'name' => 'nullable|string', |
|
290 | + 'email' => 'required|email|unique:users,email,'.\Auth::id() |
|
291 | + ]); |
|
292 | + |
|
293 | + return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture'))); |
|
294 | + } |
|
295 | 295 | } |
@@ -9,49 +9,49 @@ |
||
9 | 9 | |
10 | 10 | class OauthClientsController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * The validations rules used by the base api controller |
|
14 | - * to check before add. |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $validationRules = [ |
|
18 | - 'name' => 'required|max:255', |
|
19 | - 'redirect' => 'required|url', |
|
20 | - 'user_id' => 'required|exists:users,id', |
|
21 | - 'revoked' => 'boolean' |
|
22 | - ]; |
|
12 | + /** |
|
13 | + * The validations rules used by the base api controller |
|
14 | + * to check before add. |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $validationRules = [ |
|
18 | + 'name' => 'required|max:255', |
|
19 | + 'redirect' => 'required|url', |
|
20 | + 'user_id' => 'required|exists:users,id', |
|
21 | + 'revoked' => 'boolean' |
|
22 | + ]; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Init new object. |
|
26 | - * |
|
27 | - * @param OauthClientRepository $repo |
|
28 | - * @param CoreConfig $config |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function __construct(OauthClientRepository $repo, CoreConfig $config) |
|
32 | - { |
|
33 | - parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\OauthClient'); |
|
34 | - } |
|
24 | + /** |
|
25 | + * Init new object. |
|
26 | + * |
|
27 | + * @param OauthClientRepository $repo |
|
28 | + * @param CoreConfig $config |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function __construct(OauthClientRepository $repo, CoreConfig $config) |
|
32 | + { |
|
33 | + parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\OauthClient'); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Revoke the given client. |
|
38 | - * |
|
39 | - * @param integer $clientId Id of the client |
|
40 | - * @return \Illuminate\Http\Response |
|
41 | - */ |
|
42 | - public function revoke($clientId) |
|
43 | - { |
|
44 | - return new GeneralResource($this->repo->revoke($clientId)); |
|
45 | - } |
|
36 | + /** |
|
37 | + * Revoke the given client. |
|
38 | + * |
|
39 | + * @param integer $clientId Id of the client |
|
40 | + * @return \Illuminate\Http\Response |
|
41 | + */ |
|
42 | + public function revoke($clientId) |
|
43 | + { |
|
44 | + return new GeneralResource($this->repo->revoke($clientId)); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Un revoke the given client. |
|
49 | - * |
|
50 | - * @param integer $clientId Id of the client |
|
51 | - * @return \Illuminate\Http\Response |
|
52 | - */ |
|
53 | - public function unRevoke($clientId) |
|
54 | - { |
|
55 | - return new GeneralResource($this->repo->unRevoke($clientId)); |
|
56 | - } |
|
47 | + /** |
|
48 | + * Un revoke the given client. |
|
49 | + * |
|
50 | + * @param integer $clientId Id of the client |
|
51 | + * @return \Illuminate\Http\Response |
|
52 | + */ |
|
53 | + public function unRevoke($clientId) |
|
54 | + { |
|
55 | + return new GeneralResource($this->repo->unRevoke($clientId)); |
|
56 | + } |
|
57 | 57 | } |
@@ -2,77 +2,77 @@ |
||
2 | 2 | |
3 | 3 | class LoginProxy |
4 | 4 | { |
5 | - /** |
|
6 | - * Attempt to create an access token using user credentials. |
|
7 | - * |
|
8 | - * @param array $credentials |
|
9 | - * @param boolean $adminLogin |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function login($credentials, $adminLogin = false) |
|
13 | - { |
|
14 | - $user = \Core::users()->login($credentials, $adminLogin); |
|
15 | - $tokens = $this->proxy('password', [ |
|
16 | - 'username' => $credentials['email'], |
|
17 | - 'password' => $credentials['password'] |
|
18 | - ]); |
|
5 | + /** |
|
6 | + * Attempt to create an access token using user credentials. |
|
7 | + * |
|
8 | + * @param array $credentials |
|
9 | + * @param boolean $adminLogin |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function login($credentials, $adminLogin = false) |
|
13 | + { |
|
14 | + $user = \Core::users()->login($credentials, $adminLogin); |
|
15 | + $tokens = $this->proxy('password', [ |
|
16 | + 'username' => $credentials['email'], |
|
17 | + 'password' => $credentials['password'] |
|
18 | + ]); |
|
19 | 19 | |
20 | - return compact('user', 'tokens'); |
|
21 | - } |
|
20 | + return compact('user', 'tokens'); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Attempt to refresh the access token useing the given refresh token. |
|
25 | - * |
|
26 | - * @param string $refreshToken |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function refreshtoken($refreshToken) |
|
30 | - { |
|
31 | - return $this->proxy('refresh_token', [ |
|
32 | - 'refresh_token' => $refreshToken |
|
33 | - ]); |
|
34 | - } |
|
23 | + /** |
|
24 | + * Attempt to refresh the access token useing the given refresh token. |
|
25 | + * |
|
26 | + * @param string $refreshToken |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function refreshtoken($refreshToken) |
|
30 | + { |
|
31 | + return $this->proxy('refresh_token', [ |
|
32 | + 'refresh_token' => $refreshToken |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Proxy a request to the OAuth server. |
|
38 | - * |
|
39 | - * @param string $grantType what type of grant type should be proxied |
|
40 | - * @param array |
|
41 | - */ |
|
42 | - public function proxy($grantType, array $data = []) |
|
43 | - { |
|
44 | - $data = array_merge($data, [ |
|
45 | - 'client_id' => config('skeleton.passport_client_id'), |
|
46 | - 'client_secret' => config('skeleton.passport_client_secret'), |
|
47 | - 'grant_type' => $grantType |
|
48 | - ]); |
|
36 | + /** |
|
37 | + * Proxy a request to the OAuth server. |
|
38 | + * |
|
39 | + * @param string $grantType what type of grant type should be proxied |
|
40 | + * @param array |
|
41 | + */ |
|
42 | + public function proxy($grantType, array $data = []) |
|
43 | + { |
|
44 | + $data = array_merge($data, [ |
|
45 | + 'client_id' => config('skeleton.passport_client_id'), |
|
46 | + 'client_secret' => config('skeleton.passport_client_secret'), |
|
47 | + 'grant_type' => $grantType |
|
48 | + ]); |
|
49 | 49 | |
50 | - $response = \ApiConsumer::post('/oauth/token', $data); |
|
50 | + $response = \ApiConsumer::post('/oauth/token', $data); |
|
51 | 51 | |
52 | - if (! $response->isSuccessful()) { |
|
53 | - if ($grantType == 'refresh_token') { |
|
54 | - \ErrorHandler::invalidRefreshToken(); |
|
55 | - } |
|
52 | + if (! $response->isSuccessful()) { |
|
53 | + if ($grantType == 'refresh_token') { |
|
54 | + \ErrorHandler::invalidRefreshToken(); |
|
55 | + } |
|
56 | 56 | |
57 | - \ErrorHandler::loginFailed(); |
|
58 | - } |
|
57 | + \ErrorHandler::loginFailed(); |
|
58 | + } |
|
59 | 59 | |
60 | - $data = json_decode($response->getContent()); |
|
60 | + $data = json_decode($response->getContent()); |
|
61 | 61 | |
62 | - return [ |
|
63 | - 'access_token' => $data->access_token, |
|
64 | - 'refresh_token' => $data->refresh_token, |
|
65 | - 'expires_in' => $data->expires_in |
|
66 | - ]; |
|
67 | - } |
|
62 | + return [ |
|
63 | + 'access_token' => $data->access_token, |
|
64 | + 'refresh_token' => $data->refresh_token, |
|
65 | + 'expires_in' => $data->expires_in |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Logs out the user. We revoke access token and refresh token. |
|
71 | - * |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function logout() |
|
75 | - { |
|
76 | - \Core::users()->revokeAccessToken(\Auth::user()->token()); |
|
77 | - } |
|
69 | + /** |
|
70 | + * Logs out the user. We revoke access token and refresh token. |
|
71 | + * |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function logout() |
|
75 | + { |
|
76 | + \Core::users()->revokeAccessToken(\Auth::user()->token()); |
|
77 | + } |
|
78 | 78 | } |
@@ -6,20 +6,20 @@ |
||
6 | 6 | |
7 | 7 | class Report extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Transform the resource into an array. |
|
11 | - * |
|
12 | - * @param \Illuminate\Http\Request $request |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function toArray($request) |
|
16 | - { |
|
17 | - return [ |
|
18 | - 'id' => $this->id, |
|
19 | - 'reportName' => $this->report_name, |
|
20 | - 'viewName' => $this->view_name, |
|
21 | - 'createdAt' => $this->created_at, |
|
22 | - 'updatedAt' => $this->updated_at, |
|
23 | - ]; |
|
24 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param \Illuminate\Http\Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + return [ |
|
18 | + 'id' => $this->id, |
|
19 | + 'reportName' => $this->report_name, |
|
20 | + 'viewName' => $this->view_name, |
|
21 | + 'createdAt' => $this->created_at, |
|
22 | + 'updatedAt' => $this->updated_at, |
|
23 | + ]; |
|
24 | + } |
|
25 | 25 | } |
@@ -9,35 +9,35 @@ |
||
9 | 9 | |
10 | 10 | class ReportsController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * List of all route actions that the base api controller |
|
14 | - * will skip permissions check for them. |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $skipPermissionCheck = ['getReport']; |
|
12 | + /** |
|
13 | + * List of all route actions that the base api controller |
|
14 | + * will skip permissions check for them. |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $skipPermissionCheck = ['getReport']; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Init new object. |
|
21 | - * |
|
22 | - * @param ReportRepository $repo |
|
23 | - * @param CoreConfig $config |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | - { |
|
28 | - parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | - } |
|
19 | + /** |
|
20 | + * Init new object. |
|
21 | + * |
|
22 | + * @param ReportRepository $repo |
|
23 | + * @param CoreConfig $config |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | + { |
|
28 | + parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Render the given report name with the given conditions. |
|
33 | - * |
|
34 | - * @param \Illuminate\Http\Request $request |
|
35 | - * @param string $reportName Name of the requested report |
|
36 | - * @param integer $perPage Number of rows per page default all data. |
|
37 | - * @return \Illuminate\Http\Response |
|
38 | - */ |
|
39 | - public function getReport(Request $request, $reportName, $perPage = 0) |
|
40 | - { |
|
41 | - return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
42 | - } |
|
31 | + /** |
|
32 | + * Render the given report name with the given conditions. |
|
33 | + * |
|
34 | + * @param \Illuminate\Http\Request $request |
|
35 | + * @param string $reportName Name of the requested report |
|
36 | + * @param integer $perPage Number of rows per page default all data. |
|
37 | + * @return \Illuminate\Http\Response |
|
38 | + */ |
|
39 | + public function getReport(Request $request, $reportName, $perPage = 0) |
|
40 | + { |
|
41 | + return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
42 | + } |
|
43 | 43 | } |