@@ -7,298 +7,298 @@ |
||
7 | 7 | |
8 | 8 | class BaseApiController extends Controller |
9 | 9 | { |
10 | - /** |
|
11 | - * The config implementation. |
|
12 | - * |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $config; |
|
16 | - |
|
17 | - /** |
|
18 | - * The relations implementation. |
|
19 | - * |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $relations; |
|
23 | - |
|
24 | - /** |
|
25 | - * The repo implementation. |
|
26 | - * |
|
27 | - * @var object |
|
28 | - */ |
|
29 | - protected $repo; |
|
30 | - |
|
31 | - public function __construct() |
|
32 | - { |
|
33 | - $this->config = \CoreConfig::getConfig(); |
|
34 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
35 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
36 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
37 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
38 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
39 | - |
|
40 | - $this->middleware(function ($request, $next) { |
|
10 | + /** |
|
11 | + * The config implementation. |
|
12 | + * |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $config; |
|
16 | + |
|
17 | + /** |
|
18 | + * The relations implementation. |
|
19 | + * |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $relations; |
|
23 | + |
|
24 | + /** |
|
25 | + * The repo implementation. |
|
26 | + * |
|
27 | + * @var object |
|
28 | + */ |
|
29 | + protected $repo; |
|
30 | + |
|
31 | + public function __construct() |
|
32 | + { |
|
33 | + $this->config = \CoreConfig::getConfig(); |
|
34 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
35 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
36 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
37 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
38 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
39 | + |
|
40 | + $this->middleware(function ($request, $next) { |
|
41 | 41 | |
42 | - $this->repo = call_user_func_array("\Core::{$this->model}", []); |
|
43 | - return $next($request); |
|
44 | - }); |
|
45 | - |
|
46 | - $this->setSessions(); |
|
47 | - $this->checkPermission($route); |
|
48 | - $this->setRelations($route); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Fetch all records with relations from storage. |
|
53 | - * |
|
54 | - * @param string $sortBy The name of the column to sort by. |
|
55 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
56 | - * @return \Illuminate\Http\Response |
|
57 | - */ |
|
58 | - public function index($sortBy = 'created_at', $desc = 1) |
|
59 | - { |
|
60 | - return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Fetch the single object with relations from storage. |
|
65 | - * |
|
66 | - * @param integer $id Id of the requested model. |
|
67 | - * @return \Illuminate\Http\Response |
|
68 | - */ |
|
69 | - public function find($id) |
|
70 | - { |
|
71 | - return \Response::json($this->repo->find($id, $this->relations), 200); |
|
72 | - } |
|
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 | - return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Fetch records from the storage based on the given |
|
91 | - * condition. |
|
92 | - * |
|
93 | - * @param \Illuminate\Http\Request $request |
|
94 | - * @param string $sortBy The name of the column to sort by. |
|
95 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
96 | - * @return \Illuminate\Http\Response |
|
97 | - */ |
|
98 | - public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
99 | - { |
|
100 | - return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Fetch the first record from the storage based on the given |
|
105 | - * condition. |
|
106 | - * |
|
107 | - * @param \Illuminate\Http\Request $request |
|
108 | - * @return \Illuminate\Http\Response |
|
109 | - */ |
|
110 | - public function first(Request $request) |
|
111 | - { |
|
112 | - return \Response::json($this->repo->first($request->all(), $this->relations), 200); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Paginate all records with relations from storage. |
|
117 | - * |
|
118 | - * @param integer $perPage Number of rows per page default 15. |
|
119 | - * @param string $sortBy The name of the column to sort by. |
|
120 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
121 | - * @return \Illuminate\Http\Response |
|
122 | - */ |
|
123 | - public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
124 | - { |
|
125 | - return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Fetch all records with relations based on |
|
130 | - * the given condition from storage in pages. |
|
131 | - * |
|
132 | - * @param \Illuminate\Http\Request $request |
|
133 | - * @param integer $perPage Number of rows per page default 15. |
|
134 | - * @param string $sortBy The name of the column to sort by. |
|
135 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
136 | - * @return \Illuminate\Http\Response |
|
137 | - */ |
|
138 | - public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
139 | - { |
|
140 | - return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Save the given model to storage. |
|
145 | - * |
|
146 | - * @param \Illuminate\Http\Request $request |
|
147 | - * @return \Illuminate\Http\Response |
|
148 | - */ |
|
149 | - public function save(Request $request) |
|
150 | - { |
|
151 | - foreach ($this->validationRules as &$rule) { |
|
152 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) { |
|
153 | - $rule .= ',deleted_at,NULL'; |
|
154 | - } |
|
155 | - |
|
156 | - if ($request->has('id')) { |
|
157 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
158 | - } else { |
|
159 | - $rule = str_replace(',{id}', '', $rule); |
|
160 | - } |
|
161 | - } |
|
42 | + $this->repo = call_user_func_array("\Core::{$this->model}", []); |
|
43 | + return $next($request); |
|
44 | + }); |
|
45 | + |
|
46 | + $this->setSessions(); |
|
47 | + $this->checkPermission($route); |
|
48 | + $this->setRelations($route); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Fetch all records with relations from storage. |
|
53 | + * |
|
54 | + * @param string $sortBy The name of the column to sort by. |
|
55 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
56 | + * @return \Illuminate\Http\Response |
|
57 | + */ |
|
58 | + public function index($sortBy = 'created_at', $desc = 1) |
|
59 | + { |
|
60 | + return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Fetch the single object with relations from storage. |
|
65 | + * |
|
66 | + * @param integer $id Id of the requested model. |
|
67 | + * @return \Illuminate\Http\Response |
|
68 | + */ |
|
69 | + public function find($id) |
|
70 | + { |
|
71 | + return \Response::json($this->repo->find($id, $this->relations), 200); |
|
72 | + } |
|
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 | + return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Fetch records from the storage based on the given |
|
91 | + * condition. |
|
92 | + * |
|
93 | + * @param \Illuminate\Http\Request $request |
|
94 | + * @param string $sortBy The name of the column to sort by. |
|
95 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
96 | + * @return \Illuminate\Http\Response |
|
97 | + */ |
|
98 | + public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
99 | + { |
|
100 | + return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Fetch the first record from the storage based on the given |
|
105 | + * condition. |
|
106 | + * |
|
107 | + * @param \Illuminate\Http\Request $request |
|
108 | + * @return \Illuminate\Http\Response |
|
109 | + */ |
|
110 | + public function first(Request $request) |
|
111 | + { |
|
112 | + return \Response::json($this->repo->first($request->all(), $this->relations), 200); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Paginate all records with relations from storage. |
|
117 | + * |
|
118 | + * @param integer $perPage Number of rows per page default 15. |
|
119 | + * @param string $sortBy The name of the column to sort by. |
|
120 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
121 | + * @return \Illuminate\Http\Response |
|
122 | + */ |
|
123 | + public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
124 | + { |
|
125 | + return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Fetch all records with relations based on |
|
130 | + * the given condition from storage in pages. |
|
131 | + * |
|
132 | + * @param \Illuminate\Http\Request $request |
|
133 | + * @param integer $perPage Number of rows per page default 15. |
|
134 | + * @param string $sortBy The name of the column to sort by. |
|
135 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
136 | + * @return \Illuminate\Http\Response |
|
137 | + */ |
|
138 | + public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
139 | + { |
|
140 | + return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Save the given model to storage. |
|
145 | + * |
|
146 | + * @param \Illuminate\Http\Request $request |
|
147 | + * @return \Illuminate\Http\Response |
|
148 | + */ |
|
149 | + public function save(Request $request) |
|
150 | + { |
|
151 | + foreach ($this->validationRules as &$rule) { |
|
152 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) { |
|
153 | + $rule .= ',deleted_at,NULL'; |
|
154 | + } |
|
155 | + |
|
156 | + if ($request->has('id')) { |
|
157 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
158 | + } else { |
|
159 | + $rule = str_replace(',{id}', '', $rule); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - $this->validate($request, $this->validationRules); |
|
164 | - |
|
165 | - return \Response::json($this->repo->save($request->all()), 200); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Delete by the given id from storage. |
|
170 | - * |
|
171 | - * @param integer $id Id of the deleted model. |
|
172 | - * @return \Illuminate\Http\Response |
|
173 | - */ |
|
174 | - public function delete($id) |
|
175 | - { |
|
176 | - return \Response::json($this->repo->delete($id), 200); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Return the deleted models in pages based on the given conditions. |
|
181 | - * |
|
182 | - * @param \Illuminate\Http\Request $request |
|
183 | - * @param integer $perPage Number of rows per page default 15. |
|
184 | - * @param string $sortBy The name of the column to sort by. |
|
185 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
186 | - * @return \Illuminate\Http\Response |
|
187 | - */ |
|
188 | - public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
189 | - { |
|
190 | - return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Restore the deleted model. |
|
195 | - * |
|
196 | - * @param integer $id Id of the restored model. |
|
197 | - * @return \Illuminate\Http\Response |
|
198 | - */ |
|
199 | - public function restore($id) |
|
200 | - { |
|
201 | - return \Response::json($this->repo->restore($id), 200); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Check if the logged in user can do the given permission. |
|
206 | - * |
|
207 | - * @param string $permission |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - private function checkPermission($permission) |
|
211 | - { |
|
212 | - \Auth::shouldUse('api'); |
|
213 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
163 | + $this->validate($request, $this->validationRules); |
|
164 | + |
|
165 | + return \Response::json($this->repo->save($request->all()), 200); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Delete by the given id from storage. |
|
170 | + * |
|
171 | + * @param integer $id Id of the deleted model. |
|
172 | + * @return \Illuminate\Http\Response |
|
173 | + */ |
|
174 | + public function delete($id) |
|
175 | + { |
|
176 | + return \Response::json($this->repo->delete($id), 200); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Return the deleted models in pages based on the given conditions. |
|
181 | + * |
|
182 | + * @param \Illuminate\Http\Request $request |
|
183 | + * @param integer $perPage Number of rows per page default 15. |
|
184 | + * @param string $sortBy The name of the column to sort by. |
|
185 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
186 | + * @return \Illuminate\Http\Response |
|
187 | + */ |
|
188 | + public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
189 | + { |
|
190 | + return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Restore the deleted model. |
|
195 | + * |
|
196 | + * @param integer $id Id of the restored model. |
|
197 | + * @return \Illuminate\Http\Response |
|
198 | + */ |
|
199 | + public function restore($id) |
|
200 | + { |
|
201 | + return \Response::json($this->repo->restore($id), 200); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Check if the logged in user can do the given permission. |
|
206 | + * |
|
207 | + * @param string $permission |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + private function checkPermission($permission) |
|
211 | + { |
|
212 | + \Auth::shouldUse('api'); |
|
213 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
214 | 214 | |
215 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
216 | - $user = \Auth::user(); |
|
217 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
218 | - $isPasswordClient = $user->token()->client->password_client; |
|
219 | - $this->updateLocaleAndTimezone($user); |
|
220 | - |
|
221 | - if ($user->blocked) { |
|
222 | - \ErrorHandler::userIsBlocked(); |
|
223 | - } |
|
224 | - |
|
225 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) { |
|
226 | - } elseif (! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) { |
|
227 | - } else { |
|
228 | - \ErrorHandler::noPermissions(); |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Set sessions based on the given headers in the request. |
|
235 | - * |
|
236 | - * @return void |
|
237 | - */ |
|
238 | - private function setSessions() |
|
239 | - { |
|
240 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
241 | - |
|
242 | - $locale = \Request::header('locale'); |
|
243 | - switch ($locale) { |
|
244 | - case 'en': |
|
245 | - \App::setLocale('en'); |
|
246 | - \Session::put('locale', 'en'); |
|
247 | - break; |
|
248 | - |
|
249 | - case 'ar': |
|
250 | - \App::setLocale('ar'); |
|
251 | - \Session::put('locale', 'ar'); |
|
252 | - break; |
|
253 | - |
|
254 | - case 'all': |
|
255 | - \App::setLocale('en'); |
|
256 | - \Session::put('locale', 'all'); |
|
257 | - break; |
|
258 | - |
|
259 | - default: |
|
260 | - \App::setLocale('en'); |
|
261 | - \Session::put('locale', 'en'); |
|
262 | - break; |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Set relation based on the called api. |
|
268 | - * |
|
269 | - * @param string $route |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - private function setRelations($route) |
|
273 | - { |
|
274 | - $route = $route !== 'index' ? $route : 'list'; |
|
275 | - $relations = Arr::get($this->config['relations'], $this->model, false); |
|
276 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Update the logged in user locale and time zone. |
|
281 | - * |
|
282 | - * @param object $user |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - private function updateLocaleAndTimezone($user) |
|
286 | - { |
|
287 | - $update = false; |
|
288 | - $locale = \Session::get('locale'); |
|
289 | - $timezone = \Session::get('time-zone'); |
|
290 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
291 | - $user->locale = $locale; |
|
292 | - $update = true; |
|
293 | - } |
|
294 | - |
|
295 | - if ($timezone && $timezone !== $user->timezone) { |
|
296 | - $user->timezone = $timezone; |
|
297 | - $update = true; |
|
298 | - } |
|
299 | - |
|
300 | - if ($update) { |
|
301 | - $user->save(); |
|
302 | - } |
|
303 | - } |
|
215 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
216 | + $user = \Auth::user(); |
|
217 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
218 | + $isPasswordClient = $user->token()->client->password_client; |
|
219 | + $this->updateLocaleAndTimezone($user); |
|
220 | + |
|
221 | + if ($user->blocked) { |
|
222 | + \ErrorHandler::userIsBlocked(); |
|
223 | + } |
|
224 | + |
|
225 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) { |
|
226 | + } elseif (! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) { |
|
227 | + } else { |
|
228 | + \ErrorHandler::noPermissions(); |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Set sessions based on the given headers in the request. |
|
235 | + * |
|
236 | + * @return void |
|
237 | + */ |
|
238 | + private function setSessions() |
|
239 | + { |
|
240 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
241 | + |
|
242 | + $locale = \Request::header('locale'); |
|
243 | + switch ($locale) { |
|
244 | + case 'en': |
|
245 | + \App::setLocale('en'); |
|
246 | + \Session::put('locale', 'en'); |
|
247 | + break; |
|
248 | + |
|
249 | + case 'ar': |
|
250 | + \App::setLocale('ar'); |
|
251 | + \Session::put('locale', 'ar'); |
|
252 | + break; |
|
253 | + |
|
254 | + case 'all': |
|
255 | + \App::setLocale('en'); |
|
256 | + \Session::put('locale', 'all'); |
|
257 | + break; |
|
258 | + |
|
259 | + default: |
|
260 | + \App::setLocale('en'); |
|
261 | + \Session::put('locale', 'en'); |
|
262 | + break; |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Set relation based on the called api. |
|
268 | + * |
|
269 | + * @param string $route |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + private function setRelations($route) |
|
273 | + { |
|
274 | + $route = $route !== 'index' ? $route : 'list'; |
|
275 | + $relations = Arr::get($this->config['relations'], $this->model, false); |
|
276 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Update the logged in user locale and time zone. |
|
281 | + * |
|
282 | + * @param object $user |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + private function updateLocaleAndTimezone($user) |
|
286 | + { |
|
287 | + $update = false; |
|
288 | + $locale = \Session::get('locale'); |
|
289 | + $timezone = \Session::get('time-zone'); |
|
290 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
291 | + $user->locale = $locale; |
|
292 | + $update = true; |
|
293 | + } |
|
294 | + |
|
295 | + if ($timezone && $timezone !== $user->timezone) { |
|
296 | + $user->timezone = $timezone; |
|
297 | + $update = true; |
|
298 | + } |
|
299 | + |
|
300 | + if ($update) { |
|
301 | + $user->save(); |
|
302 | + } |
|
303 | + } |
|
304 | 304 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
38 | 38 | $route = explode('@', \Route::currentRouteAction())[1]; |
39 | 39 | |
40 | - $this->middleware(function ($request, $next) { |
|
40 | + $this->middleware(function($request, $next) { |
|
41 | 41 | |
42 | 42 | $this->repo = call_user_func_array("\Core::{$this->model}", []); |
43 | 43 | return $next($request); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | \Auth::shouldUse('api'); |
213 | 213 | $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
214 | 214 | |
215 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
215 | + if ( ! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
216 | 216 | $user = \Auth::user(); |
217 | 217 | $permission = $permission !== 'index' ? $permission : 'list'; |
218 | 218 | $isPasswordClient = $user->token()->client->password_client; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | } |
224 | 224 | |
225 | 225 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) { |
226 | - } elseif (! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) { |
|
226 | + } elseif ( ! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) { |
|
227 | 227 | } else { |
228 | 228 | \ErrorHandler::noPermissions(); |
229 | 229 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | |
295 | 295 | if ($timezone && $timezone !== $user->timezone) { |
296 | 296 | $user->timezone = $timezone; |
297 | - $update = true; |
|
297 | + $update = true; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | if ($update) { |
@@ -2,28 +2,28 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * List of error messages used in core module. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | - 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
10 | - 'noPermissions' => 'لا توجد صلاحية', |
|
11 | - 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | - 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | - 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | - 'connectionError' => 'خطأ في الاتصال', |
|
15 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
16 | - 'dbQueryError' => 'خطا في البيانات', |
|
17 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
18 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
19 | - 'userIsBlocked' => 'لقد تم حظرك', |
|
20 | - 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
21 | - 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
22 | - 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
23 | - 'invalidConfirmationCode' => 'لينك التاكيد غير صالح اة مستخدم من قبل', |
|
24 | - 'notFound' => 'ال :replace المطلوب غير موجود', |
|
25 | - 'generalError' => 'حدث خطا ما', |
|
26 | - 'emailNotConfirmed' => 'بريدك الاكتروني غير مفعل', |
|
27 | - 'emailAlreadyConfirmed' => 'البريد الاكتروني مفع بالقعل' |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | + 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
10 | + 'noPermissions' => 'لا توجد صلاحية', |
|
11 | + 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | + 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | + 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | + 'connectionError' => 'خطأ في الاتصال', |
|
15 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
16 | + 'dbQueryError' => 'خطا في البيانات', |
|
17 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
18 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
19 | + 'userIsBlocked' => 'لقد تم حظرك', |
|
20 | + 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
21 | + 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
22 | + 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
23 | + 'invalidConfirmationCode' => 'لينك التاكيد غير صالح اة مستخدم من قبل', |
|
24 | + 'notFound' => 'ال :replace المطلوب غير موجود', |
|
25 | + 'generalError' => 'حدث خطا ما', |
|
26 | + 'emailNotConfirmed' => 'بريدك الاكتروني غير مفعل', |
|
27 | + 'emailAlreadyConfirmed' => 'البريد الاكتروني مفع بالقعل' |
|
28 | 28 | |
29 | 29 | ]; |
@@ -2,28 +2,28 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * List of error messages used in core module. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'Please login before any action', |
|
9 | - 'invalidRefreshToken' => 'Invalid refresh token', |
|
10 | - 'noPermissions' => 'No permissions', |
|
11 | - 'loginFailed' => 'Wrong mail or password', |
|
12 | - 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | - 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | - 'connectionError' => 'Connection error', |
|
15 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
16 | - 'dbQueryError' => 'Please check the given inputes', |
|
17 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
18 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
19 | - 'userIsBlocked' => 'You have been blocked', |
|
20 | - 'invalidResetToken' => 'Reset password token is invalid', |
|
21 | - 'invalidResetPassword' => 'Reset password is invalid', |
|
22 | - 'invalidOldPassword' => 'Old password is invalid', |
|
23 | - 'invalidConfirmationCode' => 'Confirmation link expired or already used', |
|
24 | - 'notFound' => 'The requested :replace not found', |
|
25 | - 'generalError' => 'Something went wrong', |
|
26 | - 'emailNotConfirmed' => 'Your email isn\'t confirmed', |
|
27 | - 'emailAlreadyConfirmed' => 'Your email is already confirmed' |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'Please login before any action', |
|
9 | + 'invalidRefreshToken' => 'Invalid refresh token', |
|
10 | + 'noPermissions' => 'No permissions', |
|
11 | + 'loginFailed' => 'Wrong mail or password', |
|
12 | + 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | + 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | + 'connectionError' => 'Connection error', |
|
15 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
16 | + 'dbQueryError' => 'Please check the given inputes', |
|
17 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
18 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
19 | + 'userIsBlocked' => 'You have been blocked', |
|
20 | + 'invalidResetToken' => 'Reset password token is invalid', |
|
21 | + 'invalidResetPassword' => 'Reset password is invalid', |
|
22 | + 'invalidOldPassword' => 'Old password is invalid', |
|
23 | + 'invalidConfirmationCode' => 'Confirmation link expired or already used', |
|
24 | + 'notFound' => 'The requested :replace not found', |
|
25 | + 'generalError' => 'Something went wrong', |
|
26 | + 'emailNotConfirmed' => 'Your email isn\'t confirmed', |
|
27 | + 'emailAlreadyConfirmed' => 'Your email is already confirmed' |
|
28 | 28 | |
29 | 29 | ]; |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class CoreConfig extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'CoreConfig'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'CoreConfig'; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Media extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'Media'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'Media'; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Core extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'Core'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'Core'; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class ErrorHandler extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'ErrorHandler'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'ErrorHandler'; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class ApiConsumer extends Facade |
6 | 6 | { |
7 | - protected static function getFacadeAccessor() |
|
8 | - { |
|
9 | - return 'ApiConsumer'; |
|
10 | - } |
|
7 | + protected static function getFacadeAccessor() |
|
8 | + { |
|
9 | + return 'ApiConsumer'; |
|
10 | + } |
|
11 | 11 | } |
@@ -6,52 +6,52 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
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'); |
|
18 | - |
|
19 | - $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
20 | - $factory->load(__DIR__.'/../Database/Factories'); |
|
21 | - } |
|
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 | - return new \App\Modules\Core\Core; |
|
33 | - }); |
|
34 | - |
|
35 | - //Bind ErrorHandler Facade to the IoC Container |
|
36 | - \App::bind('ErrorHandler', function () { |
|
37 | - return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | - }); |
|
39 | - |
|
40 | - //Bind CoreConfig Facade to the IoC Container |
|
41 | - \App::bind('CoreConfig', function () { |
|
42 | - return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | - }); |
|
44 | - |
|
45 | - //Bind Mpgs Facade to the IoC Container |
|
46 | - \App::bind('Media', function () { |
|
47 | - return new \App\Modules\Core\Utl\Media; |
|
48 | - }); |
|
49 | - |
|
50 | - //Bind Mpgs Facade to the IoC Container |
|
51 | - \App::bind('ApiConsumer', function () { |
|
52 | - return new \App\Modules\Core\Utl\ApiConsumer; |
|
53 | - }); |
|
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'); |
|
18 | + |
|
19 | + $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
20 | + $factory->load(__DIR__.'/../Database/Factories'); |
|
21 | + } |
|
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 | + return new \App\Modules\Core\Core; |
|
33 | + }); |
|
34 | + |
|
35 | + //Bind ErrorHandler Facade to the IoC Container |
|
36 | + \App::bind('ErrorHandler', function () { |
|
37 | + return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | + }); |
|
39 | + |
|
40 | + //Bind CoreConfig Facade to the IoC Container |
|
41 | + \App::bind('CoreConfig', function () { |
|
42 | + return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | + }); |
|
44 | + |
|
45 | + //Bind Mpgs Facade to the IoC Container |
|
46 | + \App::bind('Media', function () { |
|
47 | + return new \App\Modules\Core\Utl\Media; |
|
48 | + }); |
|
49 | + |
|
50 | + //Bind Mpgs Facade to the IoC Container |
|
51 | + \App::bind('ApiConsumer', function () { |
|
52 | + return new \App\Modules\Core\Utl\ApiConsumer; |
|
53 | + }); |
|
54 | 54 | |
55 | - $this->app->register(RouteServiceProvider::class); |
|
56 | - } |
|
55 | + $this->app->register(RouteServiceProvider::class); |
|
56 | + } |
|
57 | 57 | } |
@@ -28,27 +28,27 @@ |
||
28 | 28 | public function register() |
29 | 29 | { |
30 | 30 | //Bind Core Facade to the IoC Container |
31 | - \App::bind('Core', function () { |
|
31 | + \App::bind('Core', function() { |
|
32 | 32 | return new \App\Modules\Core\Core; |
33 | 33 | }); |
34 | 34 | |
35 | 35 | //Bind ErrorHandler Facade to the IoC Container |
36 | - \App::bind('ErrorHandler', function () { |
|
36 | + \App::bind('ErrorHandler', function() { |
|
37 | 37 | return new \App\Modules\Core\Utl\ErrorHandler; |
38 | 38 | }); |
39 | 39 | |
40 | 40 | //Bind CoreConfig Facade to the IoC Container |
41 | - \App::bind('CoreConfig', function () { |
|
41 | + \App::bind('CoreConfig', function() { |
|
42 | 42 | return new \App\Modules\Core\Utl\CoreConfig; |
43 | 43 | }); |
44 | 44 | |
45 | 45 | //Bind Mpgs Facade to the IoC Container |
46 | - \App::bind('Media', function () { |
|
46 | + \App::bind('Media', function() { |
|
47 | 47 | return new \App\Modules\Core\Utl\Media; |
48 | 48 | }); |
49 | 49 | |
50 | 50 | //Bind Mpgs Facade to the IoC Container |
51 | - \App::bind('ApiConsumer', function () { |
|
51 | + \App::bind('ApiConsumer', function() { |
|
52 | 52 | return new \App\Modules\Core\Utl\ApiConsumer; |
53 | 53 | }); |
54 | 54 |