@@ -6,307 +6,307 @@ |
||
6 | 6 | |
7 | 7 | class BaseApiController extends Controller |
8 | 8 | { |
9 | - /** |
|
10 | - * The config implementation. |
|
11 | - * |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected $config; |
|
9 | + /** |
|
10 | + * The config implementation. |
|
11 | + * |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected $config; |
|
15 | 15 | |
16 | - /** |
|
17 | - * The relations implementation. |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $relations; |
|
16 | + /** |
|
17 | + * The relations implementation. |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $relations; |
|
22 | 22 | |
23 | - /** |
|
24 | - * The repo implementation. |
|
25 | - * |
|
26 | - * @var object |
|
27 | - */ |
|
28 | - protected $repo; |
|
23 | + /** |
|
24 | + * The repo implementation. |
|
25 | + * |
|
26 | + * @var object |
|
27 | + */ |
|
28 | + protected $repo; |
|
29 | 29 | |
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->config = \CoreConfig::getConfig(); |
|
33 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
34 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
35 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
36 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
37 | - $this->repo = call_user_func_array("\Core::{$this->model}", []); |
|
38 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->config = \CoreConfig::getConfig(); |
|
33 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
34 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
35 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
36 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
37 | + $this->repo = call_user_func_array("\Core::{$this->model}", []); |
|
38 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
39 | 39 | |
40 | - $this->checkPermission($route); |
|
41 | - $this->setRelations($route); |
|
42 | - $this->setSessions(); |
|
43 | - } |
|
40 | + $this->checkPermission($route); |
|
41 | + $this->setRelations($route); |
|
42 | + $this->setSessions(); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Fetch all records with relations from storage. |
|
47 | - * |
|
48 | - * @param string $sortBy The name of the column to sort by. |
|
49 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
50 | - * @return \Illuminate\Http\Response |
|
51 | - */ |
|
52 | - public function index($sortBy = 'created_at', $desc = 1) |
|
53 | - { |
|
54 | - if ($this->repo) |
|
55 | - { |
|
56 | - return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200); |
|
57 | - } |
|
58 | - } |
|
45 | + /** |
|
46 | + * Fetch all records with relations from storage. |
|
47 | + * |
|
48 | + * @param string $sortBy The name of the column to sort by. |
|
49 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
50 | + * @return \Illuminate\Http\Response |
|
51 | + */ |
|
52 | + public function index($sortBy = 'created_at', $desc = 1) |
|
53 | + { |
|
54 | + if ($this->repo) |
|
55 | + { |
|
56 | + return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Fetch the single object with relations from storage. |
|
62 | - * |
|
63 | - * @param integer $id Id of the requested model. |
|
64 | - * @return \Illuminate\Http\Response |
|
65 | - */ |
|
66 | - public function find($id) |
|
67 | - { |
|
68 | - if ($this->repo) |
|
69 | - { |
|
70 | - return \Response::json($this->repo->find($id, $this->relations), 200); |
|
71 | - } |
|
72 | - } |
|
60 | + /** |
|
61 | + * Fetch the single object with relations from storage. |
|
62 | + * |
|
63 | + * @param integer $id Id of the requested model. |
|
64 | + * @return \Illuminate\Http\Response |
|
65 | + */ |
|
66 | + public function find($id) |
|
67 | + { |
|
68 | + if ($this->repo) |
|
69 | + { |
|
70 | + return \Response::json($this->repo->find($id, $this->relations), 200); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Paginate all records with relations from storage |
|
76 | - * that matche the given query. |
|
77 | - * |
|
78 | - * @param string $query The search text. |
|
79 | - * @param integer $perPage Number of rows per page default 15. |
|
80 | - * @param string $sortBy The name of the column to sort by. |
|
81 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
82 | - * @return \Illuminate\Http\Response |
|
83 | - */ |
|
84 | - public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
85 | - { |
|
86 | - if ($this->repo) |
|
87 | - { |
|
88 | - return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200); |
|
89 | - } |
|
90 | - } |
|
74 | + /** |
|
75 | + * Paginate all records with relations from storage |
|
76 | + * that matche the given query. |
|
77 | + * |
|
78 | + * @param string $query The search text. |
|
79 | + * @param integer $perPage Number of rows per page default 15. |
|
80 | + * @param string $sortBy The name of the column to sort by. |
|
81 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
82 | + * @return \Illuminate\Http\Response |
|
83 | + */ |
|
84 | + public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
85 | + { |
|
86 | + if ($this->repo) |
|
87 | + { |
|
88 | + return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Fetch records from the storage based on the given |
|
94 | - * condition. |
|
95 | - * |
|
96 | - * @param \Illuminate\Http\Request $request |
|
97 | - * @param string $sortBy The name of the column to sort by. |
|
98 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
99 | - * @return \Illuminate\Http\Response |
|
100 | - */ |
|
101 | - public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
102 | - { |
|
103 | - if ($this->repo) |
|
104 | - { |
|
105 | - return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200); |
|
106 | - } |
|
107 | - } |
|
92 | + /** |
|
93 | + * Fetch records from the storage based on the given |
|
94 | + * condition. |
|
95 | + * |
|
96 | + * @param \Illuminate\Http\Request $request |
|
97 | + * @param string $sortBy The name of the column to sort by. |
|
98 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
99 | + * @return \Illuminate\Http\Response |
|
100 | + */ |
|
101 | + public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
102 | + { |
|
103 | + if ($this->repo) |
|
104 | + { |
|
105 | + return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Fetch the first record from the storage based on the given |
|
111 | - * condition. |
|
112 | - * |
|
113 | - * @param \Illuminate\Http\Request $request |
|
114 | - * @return \Illuminate\Http\Response |
|
115 | - */ |
|
116 | - public function first(Request $request) |
|
117 | - { |
|
118 | - if ($this->repo) |
|
119 | - { |
|
120 | - return \Response::json($this->repo->first($request->all(), $this->relations), 200); |
|
121 | - } |
|
122 | - } |
|
109 | + /** |
|
110 | + * Fetch the first record from the storage based on the given |
|
111 | + * condition. |
|
112 | + * |
|
113 | + * @param \Illuminate\Http\Request $request |
|
114 | + * @return \Illuminate\Http\Response |
|
115 | + */ |
|
116 | + public function first(Request $request) |
|
117 | + { |
|
118 | + if ($this->repo) |
|
119 | + { |
|
120 | + return \Response::json($this->repo->first($request->all(), $this->relations), 200); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Paginate all records with relations from storage. |
|
126 | - * |
|
127 | - * @param integer $perPage Number of rows per page default 15. |
|
128 | - * @param string $sortBy The name of the column to sort by. |
|
129 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
130 | - * @return \Illuminate\Http\Response |
|
131 | - */ |
|
132 | - public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
133 | - { |
|
134 | - if ($this->repo) |
|
135 | - { |
|
136 | - return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200); |
|
137 | - } |
|
138 | - } |
|
124 | + /** |
|
125 | + * Paginate all records with relations from storage. |
|
126 | + * |
|
127 | + * @param integer $perPage Number of rows per page default 15. |
|
128 | + * @param string $sortBy The name of the column to sort by. |
|
129 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
130 | + * @return \Illuminate\Http\Response |
|
131 | + */ |
|
132 | + public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
133 | + { |
|
134 | + if ($this->repo) |
|
135 | + { |
|
136 | + return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Fetch all records with relations based on |
|
142 | - * the given condition from storage in pages. |
|
143 | - * |
|
144 | - * @param \Illuminate\Http\Request $request |
|
145 | - * @param integer $perPage Number of rows per page default 15. |
|
146 | - * @param string $sortBy The name of the column to sort by. |
|
147 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
148 | - * @return \Illuminate\Http\Response |
|
149 | - */ |
|
150 | - public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
151 | - { |
|
152 | - if ($this->repo) |
|
153 | - { |
|
154 | - return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200); |
|
155 | - } |
|
156 | - } |
|
140 | + /** |
|
141 | + * Fetch all records with relations based on |
|
142 | + * the given condition from storage in pages. |
|
143 | + * |
|
144 | + * @param \Illuminate\Http\Request $request |
|
145 | + * @param integer $perPage Number of rows per page default 15. |
|
146 | + * @param string $sortBy The name of the column to sort by. |
|
147 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
148 | + * @return \Illuminate\Http\Response |
|
149 | + */ |
|
150 | + public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
151 | + { |
|
152 | + if ($this->repo) |
|
153 | + { |
|
154 | + return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200); |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Save the given model to storage. |
|
160 | - * |
|
161 | - * @param \Illuminate\Http\Request $request |
|
162 | - * @return \Illuminate\Http\Response |
|
163 | - */ |
|
164 | - public function save(Request $request) |
|
165 | - { |
|
166 | - foreach ($this->validationRules as &$rule) |
|
167 | - { |
|
168 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
169 | - { |
|
170 | - $rule .= ',deleted_at,NULL'; |
|
171 | - } |
|
158 | + /** |
|
159 | + * Save the given model to storage. |
|
160 | + * |
|
161 | + * @param \Illuminate\Http\Request $request |
|
162 | + * @return \Illuminate\Http\Response |
|
163 | + */ |
|
164 | + public function save(Request $request) |
|
165 | + { |
|
166 | + foreach ($this->validationRules as &$rule) |
|
167 | + { |
|
168 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
169 | + { |
|
170 | + $rule .= ',deleted_at,NULL'; |
|
171 | + } |
|
172 | 172 | |
173 | - if ($request->has('id')) |
|
174 | - { |
|
175 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
176 | - } |
|
177 | - else |
|
178 | - { |
|
179 | - $rule = str_replace(',{id}', '', $rule); |
|
180 | - } |
|
181 | - } |
|
173 | + if ($request->has('id')) |
|
174 | + { |
|
175 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
176 | + } |
|
177 | + else |
|
178 | + { |
|
179 | + $rule = str_replace(',{id}', '', $rule); |
|
180 | + } |
|
181 | + } |
|
182 | 182 | |
183 | - $this->validate($request, $this->validationRules); |
|
183 | + $this->validate($request, $this->validationRules); |
|
184 | 184 | |
185 | - if ($this->repo) |
|
186 | - { |
|
187 | - return \Response::json($this->repo->save($request->all()), 200); |
|
188 | - } |
|
189 | - } |
|
185 | + if ($this->repo) |
|
186 | + { |
|
187 | + return \Response::json($this->repo->save($request->all()), 200); |
|
188 | + } |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Delete by the given id from storage. |
|
193 | - * |
|
194 | - * @param integer $id Id of the deleted model. |
|
195 | - * @return \Illuminate\Http\Response |
|
196 | - */ |
|
197 | - public function delete($id) |
|
198 | - { |
|
199 | - if ($this->repo) |
|
200 | - { |
|
201 | - return \Response::json($this->repo->delete($id), 200); |
|
202 | - } |
|
203 | - } |
|
191 | + /** |
|
192 | + * Delete by the given id from storage. |
|
193 | + * |
|
194 | + * @param integer $id Id of the deleted model. |
|
195 | + * @return \Illuminate\Http\Response |
|
196 | + */ |
|
197 | + public function delete($id) |
|
198 | + { |
|
199 | + if ($this->repo) |
|
200 | + { |
|
201 | + return \Response::json($this->repo->delete($id), 200); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Return the deleted models in pages based on the given conditions. |
|
207 | - * |
|
208 | - * @param \Illuminate\Http\Request $request |
|
209 | - * @param integer $perPage Number of rows per page default 15. |
|
210 | - * @param string $sortBy The name of the column to sort by. |
|
211 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
212 | - * @return \Illuminate\Http\Response |
|
213 | - */ |
|
214 | - public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
215 | - { |
|
216 | - return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200); |
|
217 | - } |
|
205 | + /** |
|
206 | + * Return the deleted models in pages based on the given conditions. |
|
207 | + * |
|
208 | + * @param \Illuminate\Http\Request $request |
|
209 | + * @param integer $perPage Number of rows per page default 15. |
|
210 | + * @param string $sortBy The name of the column to sort by. |
|
211 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
212 | + * @return \Illuminate\Http\Response |
|
213 | + */ |
|
214 | + public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
215 | + { |
|
216 | + return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Restore the deleted model. |
|
221 | - * |
|
222 | - * @param integer $id Id of the restored model. |
|
223 | - * @return \Illuminate\Http\Response |
|
224 | - */ |
|
225 | - public function restore($id) |
|
226 | - { |
|
227 | - if ($this->repo) |
|
228 | - { |
|
229 | - return \Response::json($this->repo->restore($id), 200); |
|
230 | - } |
|
231 | - } |
|
219 | + /** |
|
220 | + * Restore the deleted model. |
|
221 | + * |
|
222 | + * @param integer $id Id of the restored model. |
|
223 | + * @return \Illuminate\Http\Response |
|
224 | + */ |
|
225 | + public function restore($id) |
|
226 | + { |
|
227 | + if ($this->repo) |
|
228 | + { |
|
229 | + return \Response::json($this->repo->restore($id), 200); |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Check if the logged in user can do the given permission. |
|
235 | - * |
|
236 | - * @param string $permission |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - private function checkPermission($permission) |
|
240 | - { |
|
241 | - \Auth::shouldUse('api'); |
|
242 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
233 | + /** |
|
234 | + * Check if the logged in user can do the given permission. |
|
235 | + * |
|
236 | + * @param string $permission |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + private function checkPermission($permission) |
|
240 | + { |
|
241 | + \Auth::shouldUse('api'); |
|
242 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
243 | 243 | |
244 | - if ($user = \Auth::user()) |
|
245 | - { |
|
246 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
247 | - $isPasswordClient = $user->token()->client->password_client; |
|
244 | + if ($user = \Auth::user()) |
|
245 | + { |
|
246 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
247 | + $isPasswordClient = $user->token()->client->password_client; |
|
248 | 248 | |
249 | - if ($user->blocked) |
|
250 | - { |
|
251 | - \ErrorHandler::userIsBlocked(); |
|
252 | - } |
|
249 | + if ($user->blocked) |
|
250 | + { |
|
251 | + \ErrorHandler::userIsBlocked(); |
|
252 | + } |
|
253 | 253 | |
254 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) |
|
255 | - {} |
|
256 | - elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) |
|
257 | - {} |
|
258 | - else |
|
259 | - { |
|
254 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) |
|
255 | + {} |
|
256 | + elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) |
|
257 | + {} |
|
258 | + else |
|
259 | + { |
|
260 | 260 | |
261 | - \ErrorHandler::noPermissions(); |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
261 | + \ErrorHandler::noPermissions(); |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Set sessions based on the given headers in the request. |
|
268 | - * |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - private function setSessions() |
|
272 | - { |
|
273 | - \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
266 | + /** |
|
267 | + * Set sessions based on the given headers in the request. |
|
268 | + * |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + private function setSessions() |
|
272 | + { |
|
273 | + \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
274 | 274 | |
275 | - $locale = \Request::header('locale'); |
|
276 | - switch ($locale) |
|
277 | - { |
|
278 | - case 'en': |
|
279 | - \App::setLocale('en'); |
|
280 | - \Session::put('locale', 'en'); |
|
281 | - break; |
|
275 | + $locale = \Request::header('locale'); |
|
276 | + switch ($locale) |
|
277 | + { |
|
278 | + case 'en': |
|
279 | + \App::setLocale('en'); |
|
280 | + \Session::put('locale', 'en'); |
|
281 | + break; |
|
282 | 282 | |
283 | - case 'ar': |
|
284 | - \App::setLocale('ar'); |
|
285 | - \Session::put('locale', 'ar'); |
|
286 | - break; |
|
283 | + case 'ar': |
|
284 | + \App::setLocale('ar'); |
|
285 | + \Session::put('locale', 'ar'); |
|
286 | + break; |
|
287 | 287 | |
288 | - case 'all': |
|
289 | - \App::setLocale('en'); |
|
290 | - \Session::put('locale', 'all'); |
|
291 | - break; |
|
288 | + case 'all': |
|
289 | + \App::setLocale('en'); |
|
290 | + \Session::put('locale', 'all'); |
|
291 | + break; |
|
292 | 292 | |
293 | - default: |
|
294 | - \App::setLocale('en'); |
|
295 | - \Session::put('locale', 'en'); |
|
296 | - break; |
|
297 | - } |
|
298 | - } |
|
293 | + default: |
|
294 | + \App::setLocale('en'); |
|
295 | + \Session::put('locale', 'en'); |
|
296 | + break; |
|
297 | + } |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Set relation based on the called api. |
|
302 | - * |
|
303 | - * @param string $route |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - private function setRelations($route) |
|
307 | - { |
|
308 | - $route = $route !== 'index' ? $route : 'list'; |
|
309 | - $relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
310 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
311 | - } |
|
300 | + /** |
|
301 | + * Set relation based on the called api. |
|
302 | + * |
|
303 | + * @param string $route |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + private function setRelations($route) |
|
307 | + { |
|
308 | + $route = $route !== 'index' ? $route : 'list'; |
|
309 | + $relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
310 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
311 | + } |
|
312 | 312 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
36 | 36 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
37 | 37 | $this->repo = call_user_func_array("\Core::{$this->model}", []); |
38 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
38 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
39 | 39 | |
40 | 40 | $this->checkPermission($route); |
41 | 41 | $this->setRelations($route); |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | |
254 | 254 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) |
255 | 255 | {} |
256 | - elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) |
|
256 | + elseif ( ! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) |
|
257 | 257 | {} |
258 | 258 | else |
259 | 259 | { |
@@ -173,8 +173,7 @@ discard block |
||
173 | 173 | if ($request->has('id')) |
174 | 174 | { |
175 | 175 | $rule = str_replace('{id}', $request->get('id'), $rule); |
176 | - } |
|
177 | - else |
|
176 | + } else |
|
178 | 177 | { |
179 | 178 | $rule = str_replace(',{id}', '', $rule); |
180 | 179 | } |
@@ -252,10 +251,8 @@ discard block |
||
252 | 251 | } |
253 | 252 | |
254 | 253 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) |
255 | - {} |
|
256 | - elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) |
|
257 | - {} |
|
258 | - else |
|
254 | + {} elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) |
|
255 | + {} else |
|
259 | 256 | { |
260 | 257 | |
261 | 258 | \ErrorHandler::noPermissions(); |
@@ -6,82 +6,82 @@ |
||
6 | 6 | |
7 | 7 | class OauthClientsTableSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - /** |
|
17 | - * Insert the permissions related to oauthClients table. |
|
18 | - */ |
|
19 | - \DB::table('permissions')->insert( |
|
20 | - [ |
|
21 | - /** |
|
22 | - * Users model permissions. |
|
23 | - */ |
|
24 | - [ |
|
25 | - 'name' => 'list', |
|
26 | - 'model' => 'oauthClients', |
|
27 | - 'created_at' => \DB::raw('NOW()'), |
|
28 | - 'updated_at' => \DB::raw('NOW()') |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'find', |
|
32 | - 'model' => 'oauthClients', |
|
33 | - 'created_at' => \DB::raw('NOW()'), |
|
34 | - 'updated_at' => \DB::raw('NOW()') |
|
35 | - ], |
|
36 | - [ |
|
37 | - 'name' => 'search', |
|
38 | - 'model' => 'oauthClients', |
|
39 | - 'created_at' => \DB::raw('NOW()'), |
|
40 | - 'updated_at' => \DB::raw('NOW()') |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'paginate', |
|
44 | - 'model' => 'oauthClients', |
|
45 | - 'created_at' => \DB::raw('NOW()'), |
|
46 | - 'updated_at' => \DB::raw('NOW()') |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'revoke', |
|
50 | - 'model' => 'oauthClients', |
|
51 | - 'created_at' => \DB::raw('NOW()'), |
|
52 | - 'updated_at' => \DB::raw('NOW()') |
|
53 | - ], |
|
54 | - [ |
|
55 | - 'name' => 'unRevoke', |
|
56 | - 'model' => 'oauthClients', |
|
57 | - 'created_at' => \DB::raw('NOW()'), |
|
58 | - 'updated_at' => \DB::raw('NOW()') |
|
59 | - ], |
|
60 | - [ |
|
61 | - 'name' => 'first', |
|
62 | - 'model' => 'oauthClients', |
|
63 | - 'created_at' => \DB::raw('NOW()'), |
|
64 | - 'updated_at' => \DB::raw('NOW()') |
|
65 | - ], |
|
66 | - [ |
|
67 | - 'name' => 'findby', |
|
68 | - 'model' => 'oauthClients', |
|
69 | - 'created_at' => \DB::raw('NOW()'), |
|
70 | - 'updated_at' => \DB::raw('NOW()') |
|
71 | - ], |
|
72 | - [ |
|
73 | - 'name' => 'paginateby', |
|
74 | - 'model' => 'oauthClients', |
|
75 | - 'created_at' => \DB::raw('NOW()'), |
|
76 | - 'updated_at' => \DB::raw('NOW()') |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'name' => 'save', |
|
80 | - 'model' => 'oauthClients', |
|
81 | - 'created_at' => \DB::raw('NOW()'), |
|
82 | - 'updated_at' => \DB::raw('NOW()') |
|
83 | - ] |
|
84 | - ] |
|
85 | - ); |
|
86 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + /** |
|
17 | + * Insert the permissions related to oauthClients table. |
|
18 | + */ |
|
19 | + \DB::table('permissions')->insert( |
|
20 | + [ |
|
21 | + /** |
|
22 | + * Users model permissions. |
|
23 | + */ |
|
24 | + [ |
|
25 | + 'name' => 'list', |
|
26 | + 'model' => 'oauthClients', |
|
27 | + 'created_at' => \DB::raw('NOW()'), |
|
28 | + 'updated_at' => \DB::raw('NOW()') |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'find', |
|
32 | + 'model' => 'oauthClients', |
|
33 | + 'created_at' => \DB::raw('NOW()'), |
|
34 | + 'updated_at' => \DB::raw('NOW()') |
|
35 | + ], |
|
36 | + [ |
|
37 | + 'name' => 'search', |
|
38 | + 'model' => 'oauthClients', |
|
39 | + 'created_at' => \DB::raw('NOW()'), |
|
40 | + 'updated_at' => \DB::raw('NOW()') |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'paginate', |
|
44 | + 'model' => 'oauthClients', |
|
45 | + 'created_at' => \DB::raw('NOW()'), |
|
46 | + 'updated_at' => \DB::raw('NOW()') |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'revoke', |
|
50 | + 'model' => 'oauthClients', |
|
51 | + 'created_at' => \DB::raw('NOW()'), |
|
52 | + 'updated_at' => \DB::raw('NOW()') |
|
53 | + ], |
|
54 | + [ |
|
55 | + 'name' => 'unRevoke', |
|
56 | + 'model' => 'oauthClients', |
|
57 | + 'created_at' => \DB::raw('NOW()'), |
|
58 | + 'updated_at' => \DB::raw('NOW()') |
|
59 | + ], |
|
60 | + [ |
|
61 | + 'name' => 'first', |
|
62 | + 'model' => 'oauthClients', |
|
63 | + 'created_at' => \DB::raw('NOW()'), |
|
64 | + 'updated_at' => \DB::raw('NOW()') |
|
65 | + ], |
|
66 | + [ |
|
67 | + 'name' => 'findby', |
|
68 | + 'model' => 'oauthClients', |
|
69 | + 'created_at' => \DB::raw('NOW()'), |
|
70 | + 'updated_at' => \DB::raw('NOW()') |
|
71 | + ], |
|
72 | + [ |
|
73 | + 'name' => 'paginateby', |
|
74 | + 'model' => 'oauthClients', |
|
75 | + 'created_at' => \DB::raw('NOW()'), |
|
76 | + 'updated_at' => \DB::raw('NOW()') |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'name' => 'save', |
|
80 | + 'model' => 'oauthClients', |
|
81 | + 'created_at' => \DB::raw('NOW()'), |
|
82 | + 'updated_at' => \DB::raw('NOW()') |
|
83 | + ] |
|
84 | + ] |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | } |
@@ -5,56 +5,56 @@ |
||
5 | 5 | */ |
6 | 6 | class AclUserObserver { |
7 | 7 | |
8 | - public function saving($model) |
|
9 | - { |
|
10 | - // |
|
11 | - } |
|
12 | - |
|
13 | - public function saved($model) |
|
14 | - { |
|
15 | - // |
|
16 | - } |
|
17 | - |
|
18 | - public function creating($model) |
|
19 | - { |
|
20 | - // |
|
21 | - } |
|
22 | - |
|
23 | - public function created($model) |
|
24 | - { |
|
25 | - // |
|
26 | - } |
|
27 | - |
|
28 | - public function updating($model) |
|
29 | - { |
|
30 | - // |
|
31 | - } |
|
32 | - |
|
33 | - public function updated($model) |
|
34 | - { |
|
35 | - // |
|
36 | - } |
|
37 | - |
|
38 | - public function deleting($model) |
|
39 | - { |
|
40 | - if ($model->getOriginal('id') == \Auth::id()) |
|
41 | - { |
|
42 | - \ErrorHandler::noPermissions(); |
|
43 | - } |
|
44 | - } |
|
45 | - |
|
46 | - public function deleted($model) |
|
47 | - { |
|
48 | - // |
|
49 | - } |
|
50 | - |
|
51 | - public function restoring($model) |
|
52 | - { |
|
53 | - $model->logs()->restore(); |
|
54 | - } |
|
55 | - |
|
56 | - public function restored($model) |
|
57 | - { |
|
58 | - // |
|
59 | - } |
|
8 | + public function saving($model) |
|
9 | + { |
|
10 | + // |
|
11 | + } |
|
12 | + |
|
13 | + public function saved($model) |
|
14 | + { |
|
15 | + // |
|
16 | + } |
|
17 | + |
|
18 | + public function creating($model) |
|
19 | + { |
|
20 | + // |
|
21 | + } |
|
22 | + |
|
23 | + public function created($model) |
|
24 | + { |
|
25 | + // |
|
26 | + } |
|
27 | + |
|
28 | + public function updating($model) |
|
29 | + { |
|
30 | + // |
|
31 | + } |
|
32 | + |
|
33 | + public function updated($model) |
|
34 | + { |
|
35 | + // |
|
36 | + } |
|
37 | + |
|
38 | + public function deleting($model) |
|
39 | + { |
|
40 | + if ($model->getOriginal('id') == \Auth::id()) |
|
41 | + { |
|
42 | + \ErrorHandler::noPermissions(); |
|
43 | + } |
|
44 | + } |
|
45 | + |
|
46 | + public function deleted($model) |
|
47 | + { |
|
48 | + // |
|
49 | + } |
|
50 | + |
|
51 | + public function restoring($model) |
|
52 | + { |
|
53 | + $model->logs()->restore(); |
|
54 | + } |
|
55 | + |
|
56 | + public function restored($model) |
|
57 | + { |
|
58 | + // |
|
59 | + } |
|
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -4,37 +4,37 @@ |
||
4 | 4 | |
5 | 5 | class OauthClientRepository extends AbstractRepository |
6 | 6 | { |
7 | - /** |
|
8 | - * Return the model full namespace. |
|
9 | - * |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - protected function getModel() |
|
13 | - { |
|
14 | - return 'App\Modules\V1\Acl\OauthClient'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * Return the model full namespace. |
|
9 | + * |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + protected function getModel() |
|
13 | + { |
|
14 | + return 'App\Modules\V1\Acl\OauthClient'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * Revoke the given client. |
|
19 | - * |
|
20 | - * @param integer $clientId |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function revoke($clientId) |
|
24 | - { |
|
25 | - $client = $this->find($clientId); |
|
26 | - $client->tokens()->update(['revoked' => true]); |
|
27 | - $this->save(['id'=> $clientId, 'revoked' => true]); |
|
28 | - } |
|
17 | + /** |
|
18 | + * Revoke the given client. |
|
19 | + * |
|
20 | + * @param integer $clientId |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function revoke($clientId) |
|
24 | + { |
|
25 | + $client = $this->find($clientId); |
|
26 | + $client->tokens()->update(['revoked' => true]); |
|
27 | + $this->save(['id'=> $clientId, 'revoked' => true]); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Un revoke the given client. |
|
32 | - * |
|
33 | - * @param integer $clientId |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function unRevoke($clientId) |
|
37 | - { |
|
38 | - $this->save(['id'=> $clientId, 'revoked' => false]); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Un revoke the given client. |
|
32 | + * |
|
33 | + * @param integer $clientId |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function unRevoke($clientId) |
|
37 | + { |
|
38 | + $this->save(['id'=> $clientId, 'revoked' => false]); |
|
39 | + } |
|
40 | 40 | } |
@@ -8,250 +8,250 @@ |
||
8 | 8 | |
9 | 9 | class UsersController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * The name of the model that is used by the base api controller |
|
13 | - * to preform actions like (add, edit ... etc). |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $model = 'users'; |
|
11 | + /** |
|
12 | + * The name of the model that is used by the base api controller |
|
13 | + * to preform actions like (add, edit ... etc). |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $model = 'users'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * List of all route actions that the base api controller |
|
20 | - * will skip permissions check for them. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
18 | + /** |
|
19 | + * List of all route actions that the base api controller |
|
20 | + * will skip permissions check for them. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
24 | 24 | |
25 | - /** |
|
26 | - * List of all route actions that the base api controller |
|
27 | - * will skip login check for them. |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
25 | + /** |
|
26 | + * List of all route actions that the base api controller |
|
27 | + * will skip login check for them. |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
31 | 31 | |
32 | - /** |
|
33 | - * The validations rules used by the base api controller |
|
34 | - * to check before add. |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $validationRules = [ |
|
38 | - 'name' => 'nullable|string', |
|
39 | - 'email' => 'required|email|unique:users,email,{id}', |
|
40 | - 'password' => 'nullable|min:6' |
|
41 | - ]; |
|
32 | + /** |
|
33 | + * The validations rules used by the base api controller |
|
34 | + * to check before add. |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $validationRules = [ |
|
38 | + 'name' => 'nullable|string', |
|
39 | + 'email' => 'required|email|unique:users,email,{id}', |
|
40 | + 'password' => 'nullable|min:6' |
|
41 | + ]; |
|
42 | 42 | |
43 | - /** |
|
44 | - * The loginProxy implementation. |
|
45 | - * |
|
46 | - * @var \App\Modules\V1\Acl\Proxy\LoginProxy |
|
47 | - */ |
|
48 | - protected $loginProxy; |
|
43 | + /** |
|
44 | + * The loginProxy implementation. |
|
45 | + * |
|
46 | + * @var \App\Modules\V1\Acl\Proxy\LoginProxy |
|
47 | + */ |
|
48 | + protected $loginProxy; |
|
49 | 49 | |
50 | - public function __construct(LoginProxy $loginProxy) |
|
51 | - { |
|
52 | - $this->loginProxy = $loginProxy; |
|
53 | - parent::__construct(); |
|
54 | - } |
|
50 | + public function __construct(LoginProxy $loginProxy) |
|
51 | + { |
|
52 | + $this->loginProxy = $loginProxy; |
|
53 | + parent::__construct(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Return the logged in user account. |
|
58 | - * |
|
59 | - * @return \Illuminate\Http\Response |
|
60 | - */ |
|
61 | - public function account() |
|
62 | - { |
|
63 | - return \Response::json($this->repo->account($this->relations), 200); |
|
64 | - } |
|
56 | + /** |
|
57 | + * Return the logged in user account. |
|
58 | + * |
|
59 | + * @return \Illuminate\Http\Response |
|
60 | + */ |
|
61 | + public function account() |
|
62 | + { |
|
63 | + return \Response::json($this->repo->account($this->relations), 200); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Block the user. |
|
68 | - * |
|
69 | - * @param integer $id Id of the user. |
|
70 | - * @return \Illuminate\Http\Response |
|
71 | - */ |
|
72 | - public function block($id) |
|
73 | - { |
|
74 | - return \Response::json($this->repo->block($id), 200); |
|
75 | - } |
|
66 | + /** |
|
67 | + * Block the user. |
|
68 | + * |
|
69 | + * @param integer $id Id of the user. |
|
70 | + * @return \Illuminate\Http\Response |
|
71 | + */ |
|
72 | + public function block($id) |
|
73 | + { |
|
74 | + return \Response::json($this->repo->block($id), 200); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Unblock the user. |
|
79 | - * |
|
80 | - * @param integer $id Id of the user. |
|
81 | - * @return \Illuminate\Http\Response |
|
82 | - */ |
|
83 | - public function unblock($id) |
|
84 | - { |
|
85 | - return \Response::json($this->repo->unblock($id), 200); |
|
86 | - } |
|
77 | + /** |
|
78 | + * Unblock the user. |
|
79 | + * |
|
80 | + * @param integer $id Id of the user. |
|
81 | + * @return \Illuminate\Http\Response |
|
82 | + */ |
|
83 | + public function unblock($id) |
|
84 | + { |
|
85 | + return \Response::json($this->repo->unblock($id), 200); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Logout the user. |
|
90 | - * |
|
91 | - * @return \Illuminate\Http\Response |
|
92 | - */ |
|
93 | - public function logout() |
|
94 | - { |
|
95 | - return \Response::json($this->loginProxy->logout(), 200); |
|
96 | - } |
|
88 | + /** |
|
89 | + * Logout the user. |
|
90 | + * |
|
91 | + * @return \Illuminate\Http\Response |
|
92 | + */ |
|
93 | + public function logout() |
|
94 | + { |
|
95 | + return \Response::json($this->loginProxy->logout(), 200); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Handle a registration request. |
|
100 | - * |
|
101 | - * @param \Illuminate\Http\Request $request |
|
102 | - * @return \Illuminate\Http\Response |
|
103 | - */ |
|
104 | - public function register(Request $request) |
|
105 | - { |
|
106 | - $this->validate($request, [ |
|
107 | - 'name' => 'nullable|string', |
|
108 | - 'email' => 'required|email|unique:users,email,{id}', |
|
109 | - 'password' => 'required|min:6' |
|
110 | - ]); |
|
98 | + /** |
|
99 | + * Handle a registration request. |
|
100 | + * |
|
101 | + * @param \Illuminate\Http\Request $request |
|
102 | + * @return \Illuminate\Http\Response |
|
103 | + */ |
|
104 | + public function register(Request $request) |
|
105 | + { |
|
106 | + $this->validate($request, [ |
|
107 | + 'name' => 'nullable|string', |
|
108 | + 'email' => 'required|email|unique:users,email,{id}', |
|
109 | + 'password' => 'required|min:6' |
|
110 | + ]); |
|
111 | 111 | |
112 | - return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200); |
|
113 | - } |
|
112 | + return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Handle a login request to the application. |
|
117 | - * |
|
118 | - * @param \Illuminate\Http\Request $request |
|
119 | - * @return \Illuminate\Http\Response |
|
120 | - */ |
|
121 | - public function login(Request $request) |
|
122 | - { |
|
123 | - $this->validate($request, [ |
|
124 | - 'email' => 'required|email', |
|
125 | - 'password' => 'required|min:6' |
|
126 | - ]); |
|
115 | + /** |
|
116 | + * Handle a login request to the application. |
|
117 | + * |
|
118 | + * @param \Illuminate\Http\Request $request |
|
119 | + * @return \Illuminate\Http\Response |
|
120 | + */ |
|
121 | + public function login(Request $request) |
|
122 | + { |
|
123 | + $this->validate($request, [ |
|
124 | + 'email' => 'required|email', |
|
125 | + 'password' => 'required|min:6' |
|
126 | + ]); |
|
127 | 127 | |
128 | - return \Response::json($this->loginProxy->login($request->only('email', 'password')), 200); |
|
129 | - } |
|
128 | + return \Response::json($this->loginProxy->login($request->only('email', 'password')), 200); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Handle a social login request of the none admin to the application. |
|
133 | - * |
|
134 | - * @param \Illuminate\Http\Request $request |
|
135 | - * @return \Illuminate\Http\Response |
|
136 | - */ |
|
137 | - public function loginSocial(Request $request) |
|
138 | - { |
|
139 | - $this->validate($request, [ |
|
140 | - 'auth_code' => 'required_without:access_token', |
|
141 | - 'access_token' => 'required_without:auth_code', |
|
142 | - 'type' => 'required|in:facebook,google' |
|
143 | - ]); |
|
131 | + /** |
|
132 | + * Handle a social login request of the none admin to the application. |
|
133 | + * |
|
134 | + * @param \Illuminate\Http\Request $request |
|
135 | + * @return \Illuminate\Http\Response |
|
136 | + */ |
|
137 | + public function loginSocial(Request $request) |
|
138 | + { |
|
139 | + $this->validate($request, [ |
|
140 | + 'auth_code' => 'required_without:access_token', |
|
141 | + 'access_token' => 'required_without:auth_code', |
|
142 | + 'type' => 'required|in:facebook,google' |
|
143 | + ]); |
|
144 | 144 | |
145 | - return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
146 | - } |
|
145 | + return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Assign the given groups to the given user. |
|
150 | - * |
|
151 | - * @param \Illuminate\Http\Request $request |
|
152 | - * @return \Illuminate\Http\Response |
|
153 | - */ |
|
154 | - public function assigngroups(Request $request) |
|
155 | - { |
|
156 | - $this->validate($request, [ |
|
157 | - 'group_ids' => 'required|exists:groups,id', |
|
158 | - 'user_id' => 'required|exists:users,id' |
|
159 | - ]); |
|
148 | + /** |
|
149 | + * Assign the given groups to the given user. |
|
150 | + * |
|
151 | + * @param \Illuminate\Http\Request $request |
|
152 | + * @return \Illuminate\Http\Response |
|
153 | + */ |
|
154 | + public function assigngroups(Request $request) |
|
155 | + { |
|
156 | + $this->validate($request, [ |
|
157 | + 'group_ids' => 'required|exists:groups,id', |
|
158 | + 'user_id' => 'required|exists:users,id' |
|
159 | + ]); |
|
160 | 160 | |
161 | - return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
162 | - } |
|
161 | + return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Send a reset link to the given user. |
|
166 | - * |
|
167 | - * @param \Illuminate\Http\Request $request |
|
168 | - * @return \Illuminate\Http\Response |
|
169 | - */ |
|
170 | - public function sendreset(Request $request) |
|
171 | - { |
|
172 | - $this->validate($request, ['email' => 'required|email']); |
|
164 | + /** |
|
165 | + * Send a reset link to the given user. |
|
166 | + * |
|
167 | + * @param \Illuminate\Http\Request $request |
|
168 | + * @return \Illuminate\Http\Response |
|
169 | + */ |
|
170 | + public function sendreset(Request $request) |
|
171 | + { |
|
172 | + $this->validate($request, ['email' => 'required|email']); |
|
173 | 173 | |
174 | - return \Response::json($this->repo->sendReset($request->only('email')), 200); |
|
175 | - } |
|
174 | + return \Response::json($this->repo->sendReset($request->only('email')), 200); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Reset the given user's password. |
|
179 | - * |
|
180 | - * @param \Illuminate\Http\Request $request |
|
181 | - * @return \Illuminate\Http\Response |
|
182 | - */ |
|
183 | - public function resetpassword(Request $request) |
|
184 | - { |
|
185 | - $this->validate($request, [ |
|
186 | - 'token' => 'required', |
|
187 | - 'email' => 'required|email', |
|
188 | - 'password' => 'required|confirmed|min:6', |
|
189 | - 'password_confirmation' => 'required', |
|
190 | - ]); |
|
177 | + /** |
|
178 | + * Reset the given user's password. |
|
179 | + * |
|
180 | + * @param \Illuminate\Http\Request $request |
|
181 | + * @return \Illuminate\Http\Response |
|
182 | + */ |
|
183 | + public function resetpassword(Request $request) |
|
184 | + { |
|
185 | + $this->validate($request, [ |
|
186 | + 'token' => 'required', |
|
187 | + 'email' => 'required|email', |
|
188 | + 'password' => 'required|confirmed|min:6', |
|
189 | + 'password_confirmation' => 'required', |
|
190 | + ]); |
|
191 | 191 | |
192 | - return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
193 | - } |
|
192 | + return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * Change the logged in user password. |
|
197 | - * |
|
198 | - * @param \Illuminate\Http\Request $request |
|
199 | - * @return \Illuminate\Http\Response |
|
200 | - */ |
|
201 | - public function changePassword(Request $request) |
|
202 | - { |
|
203 | - $this->validate($request, [ |
|
204 | - 'old_password' => 'required', |
|
205 | - 'password' => 'required|confirmed|min:6', |
|
206 | - 'password_confirmation' => 'required', |
|
207 | - ]); |
|
195 | + /** |
|
196 | + * Change the logged in user password. |
|
197 | + * |
|
198 | + * @param \Illuminate\Http\Request $request |
|
199 | + * @return \Illuminate\Http\Response |
|
200 | + */ |
|
201 | + public function changePassword(Request $request) |
|
202 | + { |
|
203 | + $this->validate($request, [ |
|
204 | + 'old_password' => 'required', |
|
205 | + 'password' => 'required|confirmed|min:6', |
|
206 | + 'password_confirmation' => 'required', |
|
207 | + ]); |
|
208 | 208 | |
209 | - return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
210 | - } |
|
209 | + return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * Refresh the expired login token. |
|
214 | - * |
|
215 | - * @param \Illuminate\Http\Request $request |
|
216 | - * @return \Illuminate\Http\Response |
|
217 | - */ |
|
218 | - public function refreshtoken(Request $request) |
|
219 | - { |
|
220 | - $this->validate($request, [ |
|
221 | - 'refreshtoken' => 'required', |
|
222 | - ]); |
|
212 | + /** |
|
213 | + * Refresh the expired login token. |
|
214 | + * |
|
215 | + * @param \Illuminate\Http\Request $request |
|
216 | + * @return \Illuminate\Http\Response |
|
217 | + */ |
|
218 | + public function refreshtoken(Request $request) |
|
219 | + { |
|
220 | + $this->validate($request, [ |
|
221 | + 'refreshtoken' => 'required', |
|
222 | + ]); |
|
223 | 223 | |
224 | - return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200); |
|
225 | - } |
|
224 | + return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * Paginate all users with in the given group. |
|
229 | - * |
|
230 | - * @param \Illuminate\Http\Request $request |
|
231 | - * @param string $groupName The name of the requested group. |
|
232 | - * @param integer $perPage Number of rows per page default 15. |
|
233 | - * @param string $sortBy The name of the column to sort by. |
|
234 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
235 | - * @return \Illuminate\Http\Response |
|
236 | - */ |
|
237 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
238 | - { |
|
239 | - return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
240 | - } |
|
227 | + /** |
|
228 | + * Paginate all users with in the given group. |
|
229 | + * |
|
230 | + * @param \Illuminate\Http\Request $request |
|
231 | + * @param string $groupName The name of the requested group. |
|
232 | + * @param integer $perPage Number of rows per page default 15. |
|
233 | + * @param string $sortBy The name of the column to sort by. |
|
234 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
235 | + * @return \Illuminate\Http\Response |
|
236 | + */ |
|
237 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
238 | + { |
|
239 | + return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * Save the given data to the logged in user. |
|
244 | - * |
|
245 | - * @param \Illuminate\Http\Request $request |
|
246 | - * @return \Illuminate\Http\Response |
|
247 | - */ |
|
248 | - public function saveProfile(Request $request) |
|
249 | - { |
|
250 | - $this->validate($request, [ |
|
251 | - 'name' => 'nullable|string', |
|
252 | - 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
253 | - ]); |
|
242 | + /** |
|
243 | + * Save the given data to the logged in user. |
|
244 | + * |
|
245 | + * @param \Illuminate\Http\Request $request |
|
246 | + * @return \Illuminate\Http\Response |
|
247 | + */ |
|
248 | + public function saveProfile(Request $request) |
|
249 | + { |
|
250 | + $this->validate($request, [ |
|
251 | + 'name' => 'nullable|string', |
|
252 | + 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
253 | + ]); |
|
254 | 254 | |
255 | - return \Response::json($this->repo->saveProfile($request->only('name', 'email')), 200); |
|
256 | - } |
|
255 | + return \Response::json($this->repo->saveProfile($request->only('name', 'email')), 200); |
|
256 | + } |
|
257 | 257 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * to preform actions like (add, edit ... etc). |
14 | 14 | * @var string |
15 | 15 | */ |
16 | - protected $model = 'users'; |
|
16 | + protected $model = 'users'; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * List of all route actions that the base api controller |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | * will skip login check for them. |
28 | 28 | * @var array |
29 | 29 | */ |
30 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
30 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The validations rules used by the base api controller |
34 | 34 | * to check before add. |
35 | 35 | * @var array |
36 | 36 | */ |
37 | - protected $validationRules = [ |
|
37 | + protected $validationRules = [ |
|
38 | 38 | 'name' => 'nullable|string', |
39 | 39 | 'email' => 'required|email|unique:users,email,{id}', |
40 | 40 | 'password' => 'nullable|min:6' |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | { |
250 | 250 | $this->validate($request, [ |
251 | 251 | 'name' => 'nullable|string', |
252 | - 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
252 | + 'email' => 'required|email|unique:users,email,'.\Auth::id() |
|
253 | 253 | ]); |
254 | 254 | |
255 | 255 | return \Response::json($this->repo->saveProfile($request->only('name', 'email')), 200); |
@@ -8,44 +8,44 @@ |
||
8 | 8 | |
9 | 9 | class OauthClientsController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * The name of the model that is used by the base api controller |
|
13 | - * to preform actions like (add, edit ... etc). |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $model = 'oauthClients'; |
|
11 | + /** |
|
12 | + * The name of the model that is used by the base api controller |
|
13 | + * to preform actions like (add, edit ... etc). |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $model = 'oauthClients'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * The validations rules used by the base api controller |
|
20 | - * to check before add. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $validationRules = [ |
|
24 | - 'name' => 'required|max:255', |
|
25 | - 'redirect' => 'required|url', |
|
26 | - 'user_id' => 'required|exists:users,id', |
|
27 | - 'revoked' => 'boolean' |
|
28 | - ]; |
|
18 | + /** |
|
19 | + * The validations rules used by the base api controller |
|
20 | + * to check before add. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $validationRules = [ |
|
24 | + 'name' => 'required|max:255', |
|
25 | + 'redirect' => 'required|url', |
|
26 | + 'user_id' => 'required|exists:users,id', |
|
27 | + 'revoked' => 'boolean' |
|
28 | + ]; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Revoke the given client. |
|
32 | - * |
|
33 | - * @param integer $clientId Id of the client |
|
34 | - * @return \Illuminate\Http\Response |
|
35 | - */ |
|
36 | - public function revoke($clientId) |
|
37 | - { |
|
38 | - return \Response::json($this->repo->revoke($clientId), 200); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Revoke the given client. |
|
32 | + * |
|
33 | + * @param integer $clientId Id of the client |
|
34 | + * @return \Illuminate\Http\Response |
|
35 | + */ |
|
36 | + public function revoke($clientId) |
|
37 | + { |
|
38 | + return \Response::json($this->repo->revoke($clientId), 200); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Un revoke the given client. |
|
43 | - * |
|
44 | - * @param integer $clientId Id of the client |
|
45 | - * @return \Illuminate\Http\Response |
|
46 | - */ |
|
47 | - public function unRevoke($clientId) |
|
48 | - { |
|
49 | - return \Response::json($this->repo->unRevoke($clientId), 200); |
|
50 | - } |
|
41 | + /** |
|
42 | + * Un revoke the given client. |
|
43 | + * |
|
44 | + * @param integer $clientId Id of the client |
|
45 | + * @return \Illuminate\Http\Response |
|
46 | + */ |
|
47 | + public function unRevoke($clientId) |
|
48 | + { |
|
49 | + return \Response::json($this->repo->unRevoke($clientId), 200); |
|
50 | + } |
|
51 | 51 | } |
@@ -13,14 +13,14 @@ |
||
13 | 13 | * to preform actions like (add, edit ... etc). |
14 | 14 | * @var string |
15 | 15 | */ |
16 | - protected $model = 'oauthClients'; |
|
16 | + protected $model = 'oauthClients'; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The validations rules used by the base api controller |
20 | 20 | * to check before add. |
21 | 21 | * @var array |
22 | 22 | */ |
23 | - protected $validationRules = [ |
|
23 | + protected $validationRules = [ |
|
24 | 24 | 'name' => 'required|max:255', |
25 | 25 | 'redirect' => 'required|url', |
26 | 26 | 'user_id' => 'required|exists:users,id', |
@@ -5,105 +5,105 @@ |
||
5 | 5 | |
6 | 6 | class LoginProxy |
7 | 7 | { |
8 | - private $apiConsumer; |
|
9 | - |
|
10 | - private $auth; |
|
11 | - |
|
12 | - private $db; |
|
13 | - |
|
14 | - private $request; |
|
15 | - |
|
16 | - private $userRepository; |
|
17 | - |
|
18 | - public function __construct(Application $app) |
|
19 | - { |
|
20 | - |
|
21 | - $this->userRepository = $app->make('App\Modules\V1\Acl\Repositories\UserRepository'); |
|
22 | - $this->apiConsumer = $app->make('apiconsumer'); |
|
23 | - $this->auth = $app->make('auth'); |
|
24 | - $this->db = $app->make('db'); |
|
25 | - $this->request = $app->make('request'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Attempt to create an access token using user credentials. |
|
30 | - * |
|
31 | - * @param array $credentials |
|
32 | - * @param boolean $adminLogin |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function login($credentials, $adminLogin = false) |
|
36 | - { |
|
37 | - $this->userRepository->login($credentials, $adminLogin); |
|
38 | - |
|
39 | - return $this->proxy('password', [ |
|
40 | - 'username' => $credentials['email'], |
|
41 | - 'password' => $credentials['password'] |
|
42 | - ]); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Attempt to refresh the access token useing the given refresh token. |
|
47 | - * |
|
48 | - * @param string $refreshToken |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function refreshtoken($refreshToken) |
|
52 | - { |
|
53 | - return $this->proxy('refresh_token', [ |
|
54 | - 'refresh_token' => $refreshToken |
|
55 | - ]); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Proxy a request to the OAuth server. |
|
60 | - * |
|
61 | - * @param string $grantType what type of grant type should be proxied |
|
62 | - * @param array |
|
63 | - */ |
|
64 | - public function proxy($grantType, array $data = []) |
|
65 | - { |
|
66 | - $data = array_merge($data, [ |
|
67 | - 'client_id' => env('PASSWORD_CLIENT_ID'), |
|
68 | - 'client_secret' => env('PASSWORD_CLIENT_SECRET'), |
|
69 | - 'grant_type' => $grantType |
|
70 | - ]); |
|
71 | - |
|
72 | - $response = $this->apiConsumer->post('/oauth/token', $data); |
|
73 | - |
|
74 | - if ( ! $response->isSuccessful()) |
|
75 | - { |
|
76 | - if ($grantType == 'refresh_token') |
|
77 | - { |
|
78 | - \ErrorHandler::invalidRefreshToken(); |
|
79 | - } |
|
80 | - |
|
81 | - \ErrorHandler::loginFailed(); |
|
82 | - } |
|
83 | - |
|
84 | - $data = json_decode($response->getContent()); |
|
85 | - |
|
86 | - return [ |
|
87 | - 'access_token' => $data->access_token, |
|
88 | - 'refresh_token' => $data->refresh_token, |
|
89 | - 'expires_in' => $data->expires_in |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Logs out the user. We revoke access token and refresh token. |
|
95 | - */ |
|
96 | - public function logout() |
|
97 | - { |
|
98 | - $accessToken = $this->auth->user()->token(); |
|
99 | - |
|
100 | - $this->db |
|
101 | - ->table('oauth_refresh_tokens') |
|
102 | - ->where('access_token_id', $accessToken->id) |
|
103 | - ->update([ |
|
104 | - 'revoked' => true |
|
105 | - ]); |
|
106 | - |
|
107 | - $accessToken->revoke(); |
|
108 | - } |
|
8 | + private $apiConsumer; |
|
9 | + |
|
10 | + private $auth; |
|
11 | + |
|
12 | + private $db; |
|
13 | + |
|
14 | + private $request; |
|
15 | + |
|
16 | + private $userRepository; |
|
17 | + |
|
18 | + public function __construct(Application $app) |
|
19 | + { |
|
20 | + |
|
21 | + $this->userRepository = $app->make('App\Modules\V1\Acl\Repositories\UserRepository'); |
|
22 | + $this->apiConsumer = $app->make('apiconsumer'); |
|
23 | + $this->auth = $app->make('auth'); |
|
24 | + $this->db = $app->make('db'); |
|
25 | + $this->request = $app->make('request'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Attempt to create an access token using user credentials. |
|
30 | + * |
|
31 | + * @param array $credentials |
|
32 | + * @param boolean $adminLogin |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function login($credentials, $adminLogin = false) |
|
36 | + { |
|
37 | + $this->userRepository->login($credentials, $adminLogin); |
|
38 | + |
|
39 | + return $this->proxy('password', [ |
|
40 | + 'username' => $credentials['email'], |
|
41 | + 'password' => $credentials['password'] |
|
42 | + ]); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Attempt to refresh the access token useing the given refresh token. |
|
47 | + * |
|
48 | + * @param string $refreshToken |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function refreshtoken($refreshToken) |
|
52 | + { |
|
53 | + return $this->proxy('refresh_token', [ |
|
54 | + 'refresh_token' => $refreshToken |
|
55 | + ]); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Proxy a request to the OAuth server. |
|
60 | + * |
|
61 | + * @param string $grantType what type of grant type should be proxied |
|
62 | + * @param array |
|
63 | + */ |
|
64 | + public function proxy($grantType, array $data = []) |
|
65 | + { |
|
66 | + $data = array_merge($data, [ |
|
67 | + 'client_id' => env('PASSWORD_CLIENT_ID'), |
|
68 | + 'client_secret' => env('PASSWORD_CLIENT_SECRET'), |
|
69 | + 'grant_type' => $grantType |
|
70 | + ]); |
|
71 | + |
|
72 | + $response = $this->apiConsumer->post('/oauth/token', $data); |
|
73 | + |
|
74 | + if ( ! $response->isSuccessful()) |
|
75 | + { |
|
76 | + if ($grantType == 'refresh_token') |
|
77 | + { |
|
78 | + \ErrorHandler::invalidRefreshToken(); |
|
79 | + } |
|
80 | + |
|
81 | + \ErrorHandler::loginFailed(); |
|
82 | + } |
|
83 | + |
|
84 | + $data = json_decode($response->getContent()); |
|
85 | + |
|
86 | + return [ |
|
87 | + 'access_token' => $data->access_token, |
|
88 | + 'refresh_token' => $data->refresh_token, |
|
89 | + 'expires_in' => $data->expires_in |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Logs out the user. We revoke access token and refresh token. |
|
95 | + */ |
|
96 | + public function logout() |
|
97 | + { |
|
98 | + $accessToken = $this->auth->user()->token(); |
|
99 | + |
|
100 | + $this->db |
|
101 | + ->table('oauth_refresh_tokens') |
|
102 | + ->where('access_token_id', $accessToken->id) |
|
103 | + ->update([ |
|
104 | + 'revoked' => true |
|
105 | + ]); |
|
106 | + |
|
107 | + $accessToken->revoke(); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -2,51 +2,51 @@ |
||
2 | 2 | |
3 | 3 | trait Translatable |
4 | 4 | { |
5 | - /** |
|
6 | - * Create a new model instance that is existing. |
|
7 | - * |
|
8 | - * @param array $attributes |
|
9 | - * @param string|null $connection |
|
10 | - * @return static |
|
11 | - */ |
|
12 | - public function newFromBuilder($attributes = [], $connection = null) |
|
13 | - { |
|
14 | - $model = parent::newFromBuilder($attributes, $connection); |
|
5 | + /** |
|
6 | + * Create a new model instance that is existing. |
|
7 | + * |
|
8 | + * @param array $attributes |
|
9 | + * @param string|null $connection |
|
10 | + * @return static |
|
11 | + */ |
|
12 | + public function newFromBuilder($attributes = [], $connection = null) |
|
13 | + { |
|
14 | + $model = parent::newFromBuilder($attributes, $connection); |
|
15 | 15 | |
16 | - foreach ($model->attributes AS $key => $value) |
|
17 | - { |
|
18 | - if (isset($this->translatable) && in_array($key, $this->translatable)) |
|
19 | - { |
|
20 | - $model->$key = $this->getTranslatedAttribute($key, $value); |
|
21 | - } |
|
22 | - } |
|
16 | + foreach ($model->attributes AS $key => $value) |
|
17 | + { |
|
18 | + if (isset($this->translatable) && in_array($key, $this->translatable)) |
|
19 | + { |
|
20 | + $model->$key = $this->getTranslatedAttribute($key, $value); |
|
21 | + } |
|
22 | + } |
|
23 | 23 | |
24 | - return $model; |
|
25 | - } |
|
24 | + return $model; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Returns a translatable model attribute based on the application's locale settings. |
|
29 | - * |
|
30 | - * @param $key |
|
31 | - * @param $values |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - protected function getTranslatedAttribute($key, $values) |
|
35 | - { |
|
36 | - $values = json_decode($values); |
|
37 | - $primaryLocale = \Session::get('locale'); |
|
38 | - $fallbackLocale = 'en'; |
|
27 | + /** |
|
28 | + * Returns a translatable model attribute based on the application's locale settings. |
|
29 | + * |
|
30 | + * @param $key |
|
31 | + * @param $values |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + protected function getTranslatedAttribute($key, $values) |
|
35 | + { |
|
36 | + $values = json_decode($values); |
|
37 | + $primaryLocale = \Session::get('locale'); |
|
38 | + $fallbackLocale = 'en'; |
|
39 | 39 | |
40 | - if ($primaryLocale == 'all') |
|
41 | - { |
|
42 | - return $values; |
|
43 | - } |
|
40 | + if ($primaryLocale == 'all') |
|
41 | + { |
|
42 | + return $values; |
|
43 | + } |
|
44 | 44 | |
45 | - if ( ! $primaryLocale || ! isset($values->$primaryLocale)) |
|
46 | - { |
|
47 | - return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
48 | - } |
|
45 | + if ( ! $primaryLocale || ! isset($values->$primaryLocale)) |
|
46 | + { |
|
47 | + return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
48 | + } |
|
49 | 49 | |
50 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
51 | - } |
|
50 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -7,44 +7,44 @@ |
||
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | 9 | /** |
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | 18 | |
19 | - $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
20 | - $factory->load(__DIR__.'/../Database/Factories'); |
|
21 | - } |
|
19 | + $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
20 | + $factory->load(__DIR__.'/../Database/Factories'); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - //Bind Core Facade to the IoC Container |
|
31 | - \App::bind('Core', function() |
|
32 | - { |
|
33 | - return new \App\Modules\V1\Core\Core; |
|
34 | - }); |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + //Bind Core Facade to the IoC Container |
|
31 | + \App::bind('Core', function() |
|
32 | + { |
|
33 | + return new \App\Modules\V1\Core\Core; |
|
34 | + }); |
|
35 | 35 | |
36 | - //Bind ErrorHandler Facade to the IoC Container |
|
37 | - \App::bind('ErrorHandler', function() |
|
38 | - { |
|
39 | - return new \App\Modules\V1\Core\Utl\ErrorHandler; |
|
40 | - }); |
|
36 | + //Bind ErrorHandler Facade to the IoC Container |
|
37 | + \App::bind('ErrorHandler', function() |
|
38 | + { |
|
39 | + return new \App\Modules\V1\Core\Utl\ErrorHandler; |
|
40 | + }); |
|
41 | 41 | |
42 | - //Bind CoreConfig Facade to the IoC Container |
|
43 | - \App::bind('CoreConfig', function() |
|
44 | - { |
|
45 | - return new \App\Modules\V1\Core\Utl\CoreConfig; |
|
46 | - }); |
|
42 | + //Bind CoreConfig Facade to the IoC Container |
|
43 | + \App::bind('CoreConfig', function() |
|
44 | + { |
|
45 | + return new \App\Modules\V1\Core\Utl\CoreConfig; |
|
46 | + }); |
|
47 | 47 | |
48 | - $this->app->register(RouteServiceProvider::class); |
|
49 | - } |
|
48 | + $this->app->register(RouteServiceProvider::class); |
|
49 | + } |
|
50 | 50 | } |