@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * Return the logged in user account. |
43 | 43 | * |
44 | - * @return object |
|
44 | + * @return \Illuminate\Http\JsonResponse |
|
45 | 45 | */ |
46 | 46 | public function getAccount() |
47 | 47 | { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Logout the user. |
54 | 54 | * |
55 | - * @return void |
|
55 | + * @return \Illuminate\Http\JsonResponse |
|
56 | 56 | */ |
57 | 57 | public function getLogout() |
58 | 58 | { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * Handle a registration request. |
64 | 64 | * |
65 | 65 | * @param \Illuminate\Http\Request $request |
66 | - * @return \Illuminate\Http\Response |
|
66 | + * @return \Illuminate\Http\JsonResponse |
|
67 | 67 | */ |
68 | 68 | public function postRegister(Request $request) |
69 | 69 | { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * Handle a login request to the application. |
77 | 77 | * |
78 | 78 | * @param \Illuminate\Http\Request $request |
79 | - * @return \Illuminate\Http\Response |
|
79 | + * @return \Illuminate\Http\JsonResponse|null |
|
80 | 80 | */ |
81 | 81 | public function postLogin(Request $request) |
82 | 82 | { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * Handle an assign groups to user request. |
97 | 97 | * |
98 | 98 | * @param \Illuminate\Http\Request $request |
99 | - * @return \Illuminate\Http\Response |
|
99 | + * @return \Illuminate\Http\JsonResponse |
|
100 | 100 | */ |
101 | 101 | public function postAssigngroups(Request $request) |
102 | 102 | { |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace App\Modules\Acl\Http\Controllers; |
3 | 3 | |
4 | -use Illuminate\Foundation\Http\FormRequest; |
|
5 | 4 | use App\Modules\Core\Http\Controllers\BaseApiController; |
6 | 5 | use Illuminate\Http\Request; |
7 | 6 |
@@ -7,108 +7,108 @@ |
||
7 | 7 | |
8 | 8 | class UsersController extends BaseApiController |
9 | 9 | { |
10 | - /** |
|
11 | - * The name of the model that is used by the base api controller |
|
12 | - * to preform actions like (add, edit ... etc). |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $model = 'users'; |
|
10 | + /** |
|
11 | + * The name of the model that is used by the base api controller |
|
12 | + * to preform actions like (add, edit ... etc). |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $model = 'users'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * List of all route actions that the base api controller |
|
19 | - * will skip permissions check for them. |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $skipPermissionCheck = ['account', 'logout']; |
|
17 | + /** |
|
18 | + * List of all route actions that the base api controller |
|
19 | + * will skip permissions check for them. |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $skipPermissionCheck = ['account', 'logout']; |
|
23 | 23 | |
24 | - /** |
|
25 | - * List of all route actions that the base api controller |
|
26 | - * will skip login check for them. |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $skipLoginCheck = ['login', 'register']; |
|
24 | + /** |
|
25 | + * List of all route actions that the base api controller |
|
26 | + * will skip login check for them. |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $skipLoginCheck = ['login', 'register']; |
|
30 | 30 | |
31 | - /** |
|
32 | - * The validations rules used by the base api controller |
|
33 | - * to check before add. |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $validationRules = [ |
|
37 | - 'email' => 'required|email|unique:users,email,{id}', |
|
38 | - 'password' => 'min:6' |
|
39 | - ]; |
|
31 | + /** |
|
32 | + * The validations rules used by the base api controller |
|
33 | + * to check before add. |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $validationRules = [ |
|
37 | + 'email' => 'required|email|unique:users,email,{id}', |
|
38 | + 'password' => 'min:6' |
|
39 | + ]; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Return the logged in user account. |
|
43 | - * |
|
44 | - * @return object |
|
45 | - */ |
|
46 | - public function getAccount() |
|
47 | - { |
|
48 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
49 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200); |
|
50 | - } |
|
41 | + /** |
|
42 | + * Return the logged in user account. |
|
43 | + * |
|
44 | + * @return object |
|
45 | + */ |
|
46 | + public function getAccount() |
|
47 | + { |
|
48 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
49 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Logout the user. |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function getLogout() |
|
58 | - { |
|
59 | - return \Response::json(\JWTAuth::invalidate(\JWTAuth::getToken()), 200); |
|
60 | - } |
|
52 | + /** |
|
53 | + * Logout the user. |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function getLogout() |
|
58 | + { |
|
59 | + return \Response::json(\JWTAuth::invalidate(\JWTAuth::getToken()), 200); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Handle a registration request. |
|
64 | - * |
|
65 | - * @param \Illuminate\Http\Request $request |
|
66 | - * @return \Illuminate\Http\Response |
|
67 | - */ |
|
68 | - public function postRegister(Request $request) |
|
69 | - { |
|
70 | - $this->validate($request, ['email' => 'required|email|unique:users,email,{id}', 'password' => 'required|min:6']); |
|
62 | + /** |
|
63 | + * Handle a registration request. |
|
64 | + * |
|
65 | + * @param \Illuminate\Http\Request $request |
|
66 | + * @return \Illuminate\Http\Response |
|
67 | + */ |
|
68 | + public function postRegister(Request $request) |
|
69 | + { |
|
70 | + $this->validate($request, ['email' => 'required|email|unique:users,email,{id}', 'password' => 'required|min:6']); |
|
71 | 71 | |
72 | - $credentials = $request->only('email', 'password'); |
|
73 | - $token = \JWTAuth::fromUser(\Core::users()->model->create($credentials)); |
|
74 | - return \Response::json($token, 200); |
|
75 | - } |
|
72 | + $credentials = $request->only('email', 'password'); |
|
73 | + $token = \JWTAuth::fromUser(\Core::users()->model->create($credentials)); |
|
74 | + return \Response::json($token, 200); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Handle a login request to the application. |
|
79 | - * |
|
80 | - * @param \Illuminate\Http\Request $request |
|
81 | - * @return \Illuminate\Http\Response |
|
82 | - */ |
|
83 | - public function postLogin(Request $request) |
|
84 | - { |
|
85 | - $credentials = $request->only('email', 'password'); |
|
77 | + /** |
|
78 | + * Handle a login request to the application. |
|
79 | + * |
|
80 | + * @param \Illuminate\Http\Request $request |
|
81 | + * @return \Illuminate\Http\Response |
|
82 | + */ |
|
83 | + public function postLogin(Request $request) |
|
84 | + { |
|
85 | + $credentials = $request->only('email', 'password'); |
|
86 | 86 | |
87 | - if ($token = \JWTAuth::attempt($credentials)) |
|
88 | - { |
|
89 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
90 | - return \Response::json($token, 200); |
|
91 | - } |
|
92 | - else |
|
93 | - { |
|
94 | - $error = $this->errorHandler->loginFailed(); |
|
95 | - abort($error['status'], $error['message']); |
|
96 | - } |
|
97 | - } |
|
87 | + if ($token = \JWTAuth::attempt($credentials)) |
|
88 | + { |
|
89 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
90 | + return \Response::json($token, 200); |
|
91 | + } |
|
92 | + else |
|
93 | + { |
|
94 | + $error = $this->errorHandler->loginFailed(); |
|
95 | + abort($error['status'], $error['message']); |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Handle an assign groups to user request. |
|
101 | - * |
|
102 | - * @param \Illuminate\Http\Request $request |
|
103 | - * @return \Illuminate\Http\Response |
|
104 | - */ |
|
105 | - public function postAssigngroups(Request $request) |
|
106 | - { |
|
107 | - $this->validate($request, [ |
|
108 | - 'group_ids' => 'required|exists:groups,id', |
|
109 | - 'user_id' => 'required|exists:users,id' |
|
110 | - ]); |
|
99 | + /** |
|
100 | + * Handle an assign groups to user request. |
|
101 | + * |
|
102 | + * @param \Illuminate\Http\Request $request |
|
103 | + * @return \Illuminate\Http\Response |
|
104 | + */ |
|
105 | + public function postAssigngroups(Request $request) |
|
106 | + { |
|
107 | + $this->validate($request, [ |
|
108 | + 'group_ids' => 'required|exists:groups,id', |
|
109 | + 'user_id' => 'required|exists:users,id' |
|
110 | + ]); |
|
111 | 111 | |
112 | - return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
113 | - } |
|
112 | + return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
113 | + } |
|
114 | 114 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * to preform actions like (add, edit ... etc). |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $model = 'users'; |
|
15 | + protected $model = 'users'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * List of all route actions that the base api controller |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * to check before add. |
34 | 34 | * @var array |
35 | 35 | */ |
36 | - protected $validationRules = [ |
|
36 | + protected $validationRules = [ |
|
37 | 37 | 'email' => 'required|email|unique:users,email,{id}', |
38 | 38 | 'password' => 'min:6' |
39 | 39 | ]; |
@@ -10,79 +10,79 @@ |
||
10 | 10 | |
11 | 11 | class Handler extends ExceptionHandler |
12 | 12 | { |
13 | - /** |
|
14 | - * A list of the exception types that should not be reported. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $dontReport = [ |
|
19 | - HttpException::class, |
|
20 | - ModelNotFoundException::class, |
|
21 | - ]; |
|
13 | + /** |
|
14 | + * A list of the exception types that should not be reported. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $dontReport = [ |
|
19 | + HttpException::class, |
|
20 | + ModelNotFoundException::class, |
|
21 | + ]; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Report or log an exception. |
|
25 | - * |
|
26 | - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
27 | - * |
|
28 | - * @param \Exception $e |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function report(Exception $e) |
|
32 | - { |
|
33 | - return parent::report($e); |
|
34 | - } |
|
23 | + /** |
|
24 | + * Report or log an exception. |
|
25 | + * |
|
26 | + * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
27 | + * |
|
28 | + * @param \Exception $e |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function report(Exception $e) |
|
32 | + { |
|
33 | + return parent::report($e); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Render an exception into an HTTP response. |
|
38 | - * |
|
39 | - * @param \Illuminate\Http\Request $request |
|
40 | - * @param \Exception $e |
|
41 | - * @return \Illuminate\Http\Response |
|
42 | - */ |
|
43 | - public function render($request, Exception $e) |
|
44 | - { |
|
45 | - if ($e instanceof ModelNotFoundException) { |
|
46 | - $e = new NotFoundHttpException($e->getMessage(), $e); |
|
47 | - } |
|
36 | + /** |
|
37 | + * Render an exception into an HTTP response. |
|
38 | + * |
|
39 | + * @param \Illuminate\Http\Request $request |
|
40 | + * @param \Exception $e |
|
41 | + * @return \Illuminate\Http\Response |
|
42 | + */ |
|
43 | + public function render($request, Exception $e) |
|
44 | + { |
|
45 | + if ($e instanceof ModelNotFoundException) { |
|
46 | + $e = new NotFoundHttpException($e->getMessage(), $e); |
|
47 | + } |
|
48 | 48 | |
49 | - if ($request->wantsJson()) |
|
50 | - { |
|
51 | - if ($e instanceof \Illuminate\Database\QueryException) |
|
52 | - { |
|
53 | - $error = \ErrorHandler::dbQueryError(); |
|
54 | - return \Response::json($error['message'], $error['status']); |
|
55 | - } |
|
56 | - else if ($e instanceof \predis\connection\connectionexception) |
|
57 | - { |
|
58 | - $error = \ErrorHandler::redisNotRunning(); |
|
59 | - return \Response::json($error['message'], $error['status']); |
|
60 | - } |
|
61 | - else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) |
|
62 | - { |
|
63 | - $error = \ErrorHandler::tokenExpired(); |
|
64 | - return \Response::json($error['message'], $error['status']); |
|
65 | - } |
|
66 | - else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) |
|
67 | - { |
|
68 | - $error = \ErrorHandler::noPermissions(); |
|
69 | - return \Response::json($error['message'], $error['status']); |
|
70 | - } |
|
71 | - else if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) |
|
72 | - { |
|
73 | - $error = \ErrorHandler::unAuthorized(); |
|
74 | - return \Response::json($error['message'], $error['status']); |
|
75 | - } |
|
76 | - else if ($e instanceof HttpException) |
|
77 | - { |
|
78 | - return \Response::json($e->getMessage(), $e->getStatusCode()); |
|
79 | - } |
|
80 | - else |
|
81 | - { |
|
82 | - return parent::render($request, $e); |
|
83 | - } |
|
84 | - } |
|
49 | + if ($request->wantsJson()) |
|
50 | + { |
|
51 | + if ($e instanceof \Illuminate\Database\QueryException) |
|
52 | + { |
|
53 | + $error = \ErrorHandler::dbQueryError(); |
|
54 | + return \Response::json($error['message'], $error['status']); |
|
55 | + } |
|
56 | + else if ($e instanceof \predis\connection\connectionexception) |
|
57 | + { |
|
58 | + $error = \ErrorHandler::redisNotRunning(); |
|
59 | + return \Response::json($error['message'], $error['status']); |
|
60 | + } |
|
61 | + else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) |
|
62 | + { |
|
63 | + $error = \ErrorHandler::tokenExpired(); |
|
64 | + return \Response::json($error['message'], $error['status']); |
|
65 | + } |
|
66 | + else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) |
|
67 | + { |
|
68 | + $error = \ErrorHandler::noPermissions(); |
|
69 | + return \Response::json($error['message'], $error['status']); |
|
70 | + } |
|
71 | + else if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) |
|
72 | + { |
|
73 | + $error = \ErrorHandler::unAuthorized(); |
|
74 | + return \Response::json($error['message'], $error['status']); |
|
75 | + } |
|
76 | + else if ($e instanceof HttpException) |
|
77 | + { |
|
78 | + return \Response::json($e->getMessage(), $e->getStatusCode()); |
|
79 | + } |
|
80 | + else |
|
81 | + { |
|
82 | + return parent::render($request, $e); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - return parent::render($request, $e); |
|
87 | - } |
|
86 | + return parent::render($request, $e); |
|
87 | + } |
|
88 | 88 | } |
@@ -52,32 +52,26 @@ |
||
52 | 52 | { |
53 | 53 | $error = \ErrorHandler::dbQueryError(); |
54 | 54 | return \Response::json($error['message'], $error['status']); |
55 | - } |
|
56 | - else if ($e instanceof \predis\connection\connectionexception) |
|
55 | + } else if ($e instanceof \predis\connection\connectionexception) |
|
57 | 56 | { |
58 | 57 | $error = \ErrorHandler::redisNotRunning(); |
59 | 58 | return \Response::json($error['message'], $error['status']); |
60 | - } |
|
61 | - else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) |
|
59 | + } else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) |
|
62 | 60 | { |
63 | 61 | $error = \ErrorHandler::tokenExpired(); |
64 | 62 | return \Response::json($error['message'], $error['status']); |
65 | - } |
|
66 | - else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) |
|
63 | + } else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) |
|
67 | 64 | { |
68 | 65 | $error = \ErrorHandler::noPermissions(); |
69 | 66 | return \Response::json($error['message'], $error['status']); |
70 | - } |
|
71 | - else if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) |
|
67 | + } else if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) |
|
72 | 68 | { |
73 | 69 | $error = \ErrorHandler::unAuthorized(); |
74 | 70 | return \Response::json($error['message'], $error['status']); |
75 | - } |
|
76 | - else if ($e instanceof HttpException) |
|
71 | + } else if ($e instanceof HttpException) |
|
77 | 72 | { |
78 | 73 | return \Response::json($e->getMessage(), $e->getStatusCode()); |
79 | - } |
|
80 | - else |
|
74 | + } else |
|
81 | 75 | { |
82 | 76 | return parent::render($request, $e); |
83 | 77 | } |
@@ -11,63 +11,63 @@ |
||
11 | 11 | */ |
12 | 12 | protected function getModel() |
13 | 13 | { |
14 | - $apiVersion = \Request::header('api-version') ?: 1; |
|
14 | + $apiVersion = \Request::header('api-version') ?: 1; |
|
15 | 15 | return 'App\Modules\Reporting\Report'; |
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
19 | - * Render the given report db view. |
|
20 | - * |
|
21 | - * @param integer $id |
|
22 | - * @param array $relations |
|
23 | - * @param array $columns |
|
24 | - * @return object |
|
25 | - */ |
|
26 | - public function find($id, $relations = [], $columns = array('*')) |
|
27 | - { |
|
19 | + * Render the given report db view. |
|
20 | + * |
|
21 | + * @param integer $id |
|
22 | + * @param array $relations |
|
23 | + * @param array $columns |
|
24 | + * @return object |
|
25 | + */ |
|
26 | + public function find($id, $relations = [], $columns = array('*')) |
|
27 | + { |
|
28 | 28 | $report = call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
29 | 29 | |
30 | - if ( ! $report) |
|
31 | - { |
|
32 | - $error = $this->errorHandler->notFound('report'); |
|
33 | - abort($error['status'], $error['message']); |
|
34 | - } |
|
30 | + if ( ! $report) |
|
31 | + { |
|
32 | + $error = $this->errorHandler->notFound('report'); |
|
33 | + abort($error['status'], $error['message']); |
|
34 | + } |
|
35 | 35 | |
36 | - if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
37 | - { |
|
38 | - $error = $this->errorHandler->noPermissions(); |
|
39 | - abort($error['status'], $error['message']); |
|
40 | - } |
|
36 | + if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
37 | + { |
|
38 | + $error = $this->errorHandler->noPermissions(); |
|
39 | + abort($error['status'], $error['message']); |
|
40 | + } |
|
41 | 41 | |
42 | - return \DB::table($report->view_name)->get(); |
|
43 | - } |
|
42 | + return \DB::table($report->view_name)->get(); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Render the given report db view based on the given |
|
47 | - * condition. |
|
48 | - * |
|
49 | - * @param array $conditions array of conditions |
|
50 | - * @param array $relations |
|
51 | - * @param array $colunmns |
|
52 | - * @return object |
|
53 | - */ |
|
54 | - public function first($conditions, $relations = [], $columns = array('*')) |
|
55 | - { |
|
45 | + /** |
|
46 | + * Render the given report db view based on the given |
|
47 | + * condition. |
|
48 | + * |
|
49 | + * @param array $conditions array of conditions |
|
50 | + * @param array $relations |
|
51 | + * @param array $colunmns |
|
52 | + * @return object |
|
53 | + */ |
|
54 | + public function first($conditions, $relations = [], $columns = array('*')) |
|
55 | + { |
|
56 | 56 | $conditions = $this->constructConditions($conditions); |
57 | 57 | $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
58 | 58 | |
59 | - if ( ! $report) |
|
60 | - { |
|
61 | - $error = $this->errorHandler->notFound('report'); |
|
62 | - abort($error['status'], $error['message']); |
|
63 | - } |
|
59 | + if ( ! $report) |
|
60 | + { |
|
61 | + $error = $this->errorHandler->notFound('report'); |
|
62 | + abort($error['status'], $error['message']); |
|
63 | + } |
|
64 | 64 | |
65 | - if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
66 | - { |
|
67 | - $error = $this->errorHandler->noPermissions(); |
|
68 | - abort($error['status'], $error['message']); |
|
69 | - } |
|
65 | + if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
66 | + { |
|
67 | + $error = $this->errorHandler->noPermissions(); |
|
68 | + abort($error['status'], $error['message']); |
|
69 | + } |
|
70 | 70 | |
71 | - return \DB::table($report->view_name)->get(); |
|
72 | - } |
|
71 | + return \DB::table($report->view_name)->get(); |
|
72 | + } |
|
73 | 73 | } |
@@ -2,48 +2,48 @@ |
||
2 | 2 | |
3 | 3 | class ErrorHandler |
4 | 4 | { |
5 | - public function unAuthorized() |
|
6 | - { |
|
7 | - return ['status' => 401, 'message' => 'Please login before any action']; |
|
8 | - } |
|
9 | - |
|
10 | - public function tokenExpired() |
|
11 | - { |
|
12 | - return ['status' => 401, 'message' => 'Login token expired']; |
|
13 | - } |
|
14 | - |
|
15 | - public function noPermissions() |
|
16 | - { |
|
17 | - return ['status' => 401, 'message' => 'No permissions']; |
|
18 | - } |
|
19 | - |
|
20 | - public function loginFailed() |
|
21 | - { |
|
22 | - return ['status' => 400, 'message' => 'Wrong mail or password']; |
|
23 | - } |
|
24 | - |
|
25 | - public function redisNotRunning() |
|
26 | - { |
|
27 | - return ['status' => 400, 'message' => 'Your redis notification server isn\'t running']; |
|
28 | - } |
|
29 | - |
|
30 | - public function dbQueryError() |
|
31 | - { |
|
32 | - return ['status' => 400, 'message' => 'Please check the given inputes']; |
|
33 | - } |
|
34 | - |
|
35 | - public function cannotCreateSetting() |
|
36 | - { |
|
37 | - return ['status' => 400, 'message' => 'Can\'t create setting']; |
|
38 | - } |
|
39 | - |
|
40 | - public function cannotUpdateSettingKey() |
|
41 | - { |
|
42 | - return ['status' => 400, 'message' => 'Can\'t update setting key']; |
|
43 | - } |
|
44 | - |
|
45 | - public function notFound($text) |
|
46 | - { |
|
47 | - return ['status' => 404, 'message' => 'The requested ' . $text . ' not found']; |
|
48 | - } |
|
5 | + public function unAuthorized() |
|
6 | + { |
|
7 | + return ['status' => 401, 'message' => 'Please login before any action']; |
|
8 | + } |
|
9 | + |
|
10 | + public function tokenExpired() |
|
11 | + { |
|
12 | + return ['status' => 401, 'message' => 'Login token expired']; |
|
13 | + } |
|
14 | + |
|
15 | + public function noPermissions() |
|
16 | + { |
|
17 | + return ['status' => 401, 'message' => 'No permissions']; |
|
18 | + } |
|
19 | + |
|
20 | + public function loginFailed() |
|
21 | + { |
|
22 | + return ['status' => 400, 'message' => 'Wrong mail or password']; |
|
23 | + } |
|
24 | + |
|
25 | + public function redisNotRunning() |
|
26 | + { |
|
27 | + return ['status' => 400, 'message' => 'Your redis notification server isn\'t running']; |
|
28 | + } |
|
29 | + |
|
30 | + public function dbQueryError() |
|
31 | + { |
|
32 | + return ['status' => 400, 'message' => 'Please check the given inputes']; |
|
33 | + } |
|
34 | + |
|
35 | + public function cannotCreateSetting() |
|
36 | + { |
|
37 | + return ['status' => 400, 'message' => 'Can\'t create setting']; |
|
38 | + } |
|
39 | + |
|
40 | + public function cannotUpdateSettingKey() |
|
41 | + { |
|
42 | + return ['status' => 400, 'message' => 'Can\'t update setting key']; |
|
43 | + } |
|
44 | + |
|
45 | + public function notFound($text) |
|
46 | + { |
|
47 | + return ['status' => 404, 'message' => 'The requested ' . $text . ' not found']; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -9,238 +9,238 @@ |
||
9 | 9 | |
10 | 10 | class BaseApiController extends Controller |
11 | 11 | { |
12 | - /** |
|
13 | - * The errorHandler implementation. |
|
14 | - * |
|
15 | - * @var errorHandler |
|
16 | - */ |
|
17 | - protected $errorHandler; |
|
18 | - |
|
19 | - /** |
|
20 | - * The config implementation. |
|
21 | - * |
|
22 | - * @var config |
|
23 | - */ |
|
24 | - protected $config; |
|
25 | - |
|
26 | - /** |
|
27 | - * The model implementation. |
|
28 | - * |
|
29 | - * @var model |
|
30 | - */ |
|
31 | - protected $model; |
|
32 | - |
|
33 | - /** |
|
34 | - * Create new BaseApiController instance. |
|
35 | - * |
|
36 | - * @param errorHandler |
|
37 | - */ |
|
38 | - public function __construct(ErrorHandler $errorHandler, CoreConfig $config) |
|
39 | - { |
|
40 | - \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
12 | + /** |
|
13 | + * The errorHandler implementation. |
|
14 | + * |
|
15 | + * @var errorHandler |
|
16 | + */ |
|
17 | + protected $errorHandler; |
|
18 | + |
|
19 | + /** |
|
20 | + * The config implementation. |
|
21 | + * |
|
22 | + * @var config |
|
23 | + */ |
|
24 | + protected $config; |
|
25 | + |
|
26 | + /** |
|
27 | + * The model implementation. |
|
28 | + * |
|
29 | + * @var model |
|
30 | + */ |
|
31 | + protected $model; |
|
32 | + |
|
33 | + /** |
|
34 | + * Create new BaseApiController instance. |
|
35 | + * |
|
36 | + * @param errorHandler |
|
37 | + */ |
|
38 | + public function __construct(ErrorHandler $errorHandler, CoreConfig $config) |
|
39 | + { |
|
40 | + \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
41 | 41 | |
42 | - $this->errorHandler = $errorHandler; |
|
43 | - $this->config = $config->getConfig(); |
|
42 | + $this->errorHandler = $errorHandler; |
|
43 | + $this->config = $config->getConfig(); |
|
44 | 44 | |
45 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
46 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
47 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
48 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
45 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
46 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
47 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
48 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
49 | 49 | |
50 | - $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
51 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
52 | - $this->checkPermission(explode('_', snake_case($route))[1]); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Fetch all records with relations from model repository. |
|
57 | - * |
|
58 | - * @param string $sortBy |
|
59 | - * @param boolean $desc |
|
60 | - * @return \Illuminate\Http\Response |
|
61 | - */ |
|
62 | - public function getIndex() |
|
63 | - { |
|
64 | - if ($this->model) |
|
65 | - { |
|
66 | - $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
67 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Fetch the single object with relations from model repository. |
|
73 | - * |
|
74 | - * @param integer $id |
|
75 | - * @return \Illuminate\Http\Response |
|
76 | - */ |
|
77 | - public function getFind($id) |
|
78 | - { |
|
79 | - if ($this->model) |
|
80 | - { |
|
81 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
82 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Paginate all records with relations from model repository |
|
88 | - * that matche the given query. |
|
89 | - * |
|
90 | - * @param string $query |
|
91 | - * @param integer $perPage |
|
92 | - * @param string $sortBy |
|
93 | - * @param boolean $desc |
|
94 | - * @return \Illuminate\Http\Response |
|
95 | - */ |
|
96 | - public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
97 | - { |
|
98 | - if ($this->model) |
|
99 | - { |
|
100 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
101 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Fetch records from the storage based on the given |
|
107 | - * condition. |
|
108 | - * |
|
109 | - * @param \Illuminate\Http\Request $request |
|
110 | - * @param string $sortBy |
|
111 | - * @param boolean $desc |
|
112 | - * @return \Illuminate\Http\Response |
|
113 | - */ |
|
114 | - public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
115 | - { |
|
116 | - if ($this->model) |
|
117 | - { |
|
118 | - $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
119 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Fetch the first record from the storage based on the given |
|
125 | - * condition. |
|
126 | - * |
|
127 | - * @param \Illuminate\Http\Request $request |
|
128 | - * @return \Illuminate\Http\Response |
|
129 | - */ |
|
130 | - public function postFirst(Request $request) |
|
131 | - { |
|
132 | - if ($this->model) |
|
133 | - { |
|
134 | - $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
135 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Paginate all records with relations from model repository. |
|
141 | - * |
|
142 | - * @param integer $perPage |
|
143 | - * @param string $sortBy |
|
144 | - * @param boolean $desc |
|
145 | - * @return \Illuminate\Http\Response |
|
146 | - */ |
|
147 | - public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
148 | - { |
|
149 | - if ($this->model) |
|
150 | - { |
|
151 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
152 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Fetch all records with relations based on |
|
158 | - * the given condition from storage in pages. |
|
159 | - * |
|
160 | - * @param \Illuminate\Http\Request $request |
|
161 | - * @param integer $perPage |
|
162 | - * @param string $sortBy |
|
163 | - * @param boolean $desc |
|
164 | - * @return \Illuminate\Http\Response |
|
165 | - */ |
|
166 | - public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
167 | - { |
|
168 | - if ($this->model) |
|
169 | - { |
|
170 | - $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
171 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Save the given model to repository. |
|
177 | - * |
|
178 | - * @param \Illuminate\Http\Request $request |
|
179 | - * @return \Illuminate\Http\Response |
|
180 | - */ |
|
181 | - public function postSave(Request $request) |
|
182 | - { |
|
183 | - foreach ($this->validationRules as &$rule) |
|
184 | - { |
|
185 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
186 | - { |
|
187 | - $rule .= ',deleted_at,NULL'; |
|
188 | - } |
|
189 | - |
|
190 | - if ($request->has('id')) |
|
191 | - { |
|
192 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
193 | - } |
|
194 | - else |
|
195 | - { |
|
196 | - $rule = str_replace(',{id}', '', $rule); |
|
197 | - } |
|
198 | - } |
|
50 | + $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
51 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
52 | + $this->checkPermission(explode('_', snake_case($route))[1]); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Fetch all records with relations from model repository. |
|
57 | + * |
|
58 | + * @param string $sortBy |
|
59 | + * @param boolean $desc |
|
60 | + * @return \Illuminate\Http\Response |
|
61 | + */ |
|
62 | + public function getIndex() |
|
63 | + { |
|
64 | + if ($this->model) |
|
65 | + { |
|
66 | + $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
67 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Fetch the single object with relations from model repository. |
|
73 | + * |
|
74 | + * @param integer $id |
|
75 | + * @return \Illuminate\Http\Response |
|
76 | + */ |
|
77 | + public function getFind($id) |
|
78 | + { |
|
79 | + if ($this->model) |
|
80 | + { |
|
81 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
82 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Paginate all records with relations from model repository |
|
88 | + * that matche the given query. |
|
89 | + * |
|
90 | + * @param string $query |
|
91 | + * @param integer $perPage |
|
92 | + * @param string $sortBy |
|
93 | + * @param boolean $desc |
|
94 | + * @return \Illuminate\Http\Response |
|
95 | + */ |
|
96 | + public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
97 | + { |
|
98 | + if ($this->model) |
|
99 | + { |
|
100 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
101 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Fetch records from the storage based on the given |
|
107 | + * condition. |
|
108 | + * |
|
109 | + * @param \Illuminate\Http\Request $request |
|
110 | + * @param string $sortBy |
|
111 | + * @param boolean $desc |
|
112 | + * @return \Illuminate\Http\Response |
|
113 | + */ |
|
114 | + public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
115 | + { |
|
116 | + if ($this->model) |
|
117 | + { |
|
118 | + $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
119 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Fetch the first record from the storage based on the given |
|
125 | + * condition. |
|
126 | + * |
|
127 | + * @param \Illuminate\Http\Request $request |
|
128 | + * @return \Illuminate\Http\Response |
|
129 | + */ |
|
130 | + public function postFirst(Request $request) |
|
131 | + { |
|
132 | + if ($this->model) |
|
133 | + { |
|
134 | + $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
135 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Paginate all records with relations from model repository. |
|
141 | + * |
|
142 | + * @param integer $perPage |
|
143 | + * @param string $sortBy |
|
144 | + * @param boolean $desc |
|
145 | + * @return \Illuminate\Http\Response |
|
146 | + */ |
|
147 | + public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
148 | + { |
|
149 | + if ($this->model) |
|
150 | + { |
|
151 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
152 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Fetch all records with relations based on |
|
158 | + * the given condition from storage in pages. |
|
159 | + * |
|
160 | + * @param \Illuminate\Http\Request $request |
|
161 | + * @param integer $perPage |
|
162 | + * @param string $sortBy |
|
163 | + * @param boolean $desc |
|
164 | + * @return \Illuminate\Http\Response |
|
165 | + */ |
|
166 | + public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
167 | + { |
|
168 | + if ($this->model) |
|
169 | + { |
|
170 | + $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
171 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Save the given model to repository. |
|
177 | + * |
|
178 | + * @param \Illuminate\Http\Request $request |
|
179 | + * @return \Illuminate\Http\Response |
|
180 | + */ |
|
181 | + public function postSave(Request $request) |
|
182 | + { |
|
183 | + foreach ($this->validationRules as &$rule) |
|
184 | + { |
|
185 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
186 | + { |
|
187 | + $rule .= ',deleted_at,NULL'; |
|
188 | + } |
|
189 | + |
|
190 | + if ($request->has('id')) |
|
191 | + { |
|
192 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
193 | + } |
|
194 | + else |
|
195 | + { |
|
196 | + $rule = str_replace(',{id}', '', $rule); |
|
197 | + } |
|
198 | + } |
|
199 | 199 | |
200 | - $this->validate($request, $this->validationRules); |
|
201 | - |
|
202 | - if ($this->model) |
|
203 | - { |
|
204 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Delete by the given id from model repository. |
|
210 | - * |
|
211 | - * @param integer $id |
|
212 | - * @return \Illuminate\Http\Response |
|
213 | - */ |
|
214 | - public function getDelete($id) |
|
215 | - { |
|
216 | - if ($this->model) |
|
217 | - { |
|
218 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Check if the logged in user can do the given permission. |
|
224 | - * |
|
225 | - * @param string $permission |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - private function checkPermission($permission) |
|
229 | - { |
|
230 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
231 | - if ($permission == 'method') |
|
232 | - { |
|
233 | - $error = $this->errorHandler->notFound('method'); |
|
234 | - abort($error['status'], $error['message']); |
|
235 | - } |
|
236 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
237 | - { |
|
238 | - \JWTAuth::parseToken()->authenticate(); |
|
239 | - if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
240 | - { |
|
241 | - $error = $this->errorHandler->noPermissions(); |
|
242 | - abort($error['status'], $error['message']); |
|
243 | - } |
|
244 | - } |
|
245 | - } |
|
200 | + $this->validate($request, $this->validationRules); |
|
201 | + |
|
202 | + if ($this->model) |
|
203 | + { |
|
204 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Delete by the given id from model repository. |
|
210 | + * |
|
211 | + * @param integer $id |
|
212 | + * @return \Illuminate\Http\Response |
|
213 | + */ |
|
214 | + public function getDelete($id) |
|
215 | + { |
|
216 | + if ($this->model) |
|
217 | + { |
|
218 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Check if the logged in user can do the given permission. |
|
224 | + * |
|
225 | + * @param string $permission |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + private function checkPermission($permission) |
|
229 | + { |
|
230 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
231 | + if ($permission == 'method') |
|
232 | + { |
|
233 | + $error = $this->errorHandler->notFound('method'); |
|
234 | + abort($error['status'], $error['message']); |
|
235 | + } |
|
236 | + else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
237 | + { |
|
238 | + \JWTAuth::parseToken()->authenticate(); |
|
239 | + if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
240 | + { |
|
241 | + $error = $this->errorHandler->noPermissions(); |
|
242 | + abort($error['status'], $error['message']); |
|
243 | + } |
|
244 | + } |
|
245 | + } |
|
246 | 246 | } |
@@ -190,8 +190,7 @@ discard block |
||
190 | 190 | if ($request->has('id')) |
191 | 191 | { |
192 | 192 | $rule = str_replace('{id}', $request->get('id'), $rule); |
193 | - } |
|
194 | - else |
|
193 | + } else |
|
195 | 194 | { |
196 | 195 | $rule = str_replace(',{id}', '', $rule); |
197 | 196 | } |
@@ -232,8 +231,7 @@ discard block |
||
232 | 231 | { |
233 | 232 | $error = $this->errorHandler->notFound('method'); |
234 | 233 | abort($error['status'], $error['message']); |
235 | - } |
|
236 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
234 | + } else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
237 | 235 | { |
238 | 236 | \JWTAuth::parseToken()->authenticate(); |
239 | 237 | if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
@@ -2,18 +2,18 @@ |
||
2 | 2 | |
3 | 3 | class Log |
4 | 4 | { |
5 | - public function saveLog($action, $item_name, $item_type, $item_id, $model = false) |
|
6 | - { |
|
7 | - if (\Core::logs() && $item_name !== 'Log') |
|
8 | - { |
|
9 | - $item_name = $item_name; |
|
10 | - \Core::logs()->save([ |
|
11 | - 'action' => $action, |
|
12 | - 'item_name' => $item_name, |
|
13 | - 'item_type' => $item_type, |
|
14 | - 'item_id' => $item_id, |
|
15 | - 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
16 | - ], false, false); |
|
17 | - } |
|
18 | - } |
|
5 | + public function saveLog($action, $item_name, $item_type, $item_id, $model = false) |
|
6 | + { |
|
7 | + if (\Core::logs() && $item_name !== 'Log') |
|
8 | + { |
|
9 | + $item_name = $item_name; |
|
10 | + \Core::logs()->save([ |
|
11 | + 'action' => $action, |
|
12 | + 'item_name' => $item_name, |
|
13 | + 'item_type' => $item_type, |
|
14 | + 'item_id' => $item_id, |
|
15 | + 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
16 | + ], false, false); |
|
17 | + } |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -12,191 +12,191 @@ discard block |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - /** |
|
16 | - * Delete previous permissions. |
|
17 | - */ |
|
15 | + /** |
|
16 | + * Delete previous permissions. |
|
17 | + */ |
|
18 | 18 | DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->delete(); |
19 | 19 | |
20 | 20 | /** |
21 | - * Insert the permissions related to this module. |
|
22 | - */ |
|
23 | - DB::table('permissions')->insert( |
|
24 | - [ |
|
25 | - /** |
|
26 | - * Users model permissions. |
|
27 | - */ |
|
28 | - [ |
|
29 | - 'name' => 'save', |
|
30 | - 'model' => 'users', |
|
31 | - 'created_at' => \DB::raw('NOW()'), |
|
32 | - 'updated_at' => \DB::raw('NOW()') |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'delete', |
|
36 | - 'model' => 'users', |
|
37 | - 'created_at' => \DB::raw('NOW()'), |
|
38 | - 'updated_at' => \DB::raw('NOW()') |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'name' => 'find', |
|
42 | - 'model' => 'users', |
|
43 | - 'created_at' => \DB::raw('NOW()'), |
|
44 | - 'updated_at' => \DB::raw('NOW()') |
|
45 | - ], |
|
46 | - [ |
|
47 | - 'name' => 'list', |
|
48 | - 'model' => 'users', |
|
49 | - 'created_at' => \DB::raw('NOW()'), |
|
50 | - 'updated_at' => \DB::raw('NOW()') |
|
51 | - ], |
|
52 | - [ |
|
53 | - 'name' => 'search', |
|
54 | - 'model' => 'users', |
|
55 | - 'created_at' => \DB::raw('NOW()'), |
|
56 | - 'updated_at' => \DB::raw('NOW()') |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'findby', |
|
60 | - 'model' => 'users', |
|
61 | - 'created_at' => \DB::raw('NOW()'), |
|
62 | - 'updated_at' => \DB::raw('NOW()') |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name' => 'first', |
|
66 | - 'model' => 'users', |
|
67 | - 'created_at' => \DB::raw('NOW()'), |
|
68 | - 'updated_at' => \DB::raw('NOW()') |
|
69 | - ], |
|
70 | - [ |
|
71 | - 'name' => 'paginate', |
|
72 | - 'model' => 'users', |
|
73 | - 'created_at' => \DB::raw('NOW()'), |
|
74 | - 'updated_at' => \DB::raw('NOW()') |
|
75 | - ], |
|
76 | - [ |
|
77 | - 'name' => 'paginateby', |
|
78 | - 'model' => 'users', |
|
79 | - 'created_at' => \DB::raw('NOW()'), |
|
80 | - 'updated_at' => \DB::raw('NOW()') |
|
81 | - ], |
|
82 | - [ |
|
83 | - 'name' => 'assigngroups', |
|
84 | - 'model' => 'users', |
|
85 | - 'created_at' => \DB::raw('NOW()'), |
|
86 | - 'updated_at' => \DB::raw('NOW()') |
|
87 | - ], |
|
21 | + * Insert the permissions related to this module. |
|
22 | + */ |
|
23 | + DB::table('permissions')->insert( |
|
24 | + [ |
|
25 | + /** |
|
26 | + * Users model permissions. |
|
27 | + */ |
|
28 | + [ |
|
29 | + 'name' => 'save', |
|
30 | + 'model' => 'users', |
|
31 | + 'created_at' => \DB::raw('NOW()'), |
|
32 | + 'updated_at' => \DB::raw('NOW()') |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'delete', |
|
36 | + 'model' => 'users', |
|
37 | + 'created_at' => \DB::raw('NOW()'), |
|
38 | + 'updated_at' => \DB::raw('NOW()') |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'name' => 'find', |
|
42 | + 'model' => 'users', |
|
43 | + 'created_at' => \DB::raw('NOW()'), |
|
44 | + 'updated_at' => \DB::raw('NOW()') |
|
45 | + ], |
|
46 | + [ |
|
47 | + 'name' => 'list', |
|
48 | + 'model' => 'users', |
|
49 | + 'created_at' => \DB::raw('NOW()'), |
|
50 | + 'updated_at' => \DB::raw('NOW()') |
|
51 | + ], |
|
52 | + [ |
|
53 | + 'name' => 'search', |
|
54 | + 'model' => 'users', |
|
55 | + 'created_at' => \DB::raw('NOW()'), |
|
56 | + 'updated_at' => \DB::raw('NOW()') |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'findby', |
|
60 | + 'model' => 'users', |
|
61 | + 'created_at' => \DB::raw('NOW()'), |
|
62 | + 'updated_at' => \DB::raw('NOW()') |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name' => 'first', |
|
66 | + 'model' => 'users', |
|
67 | + 'created_at' => \DB::raw('NOW()'), |
|
68 | + 'updated_at' => \DB::raw('NOW()') |
|
69 | + ], |
|
70 | + [ |
|
71 | + 'name' => 'paginate', |
|
72 | + 'model' => 'users', |
|
73 | + 'created_at' => \DB::raw('NOW()'), |
|
74 | + 'updated_at' => \DB::raw('NOW()') |
|
75 | + ], |
|
76 | + [ |
|
77 | + 'name' => 'paginateby', |
|
78 | + 'model' => 'users', |
|
79 | + 'created_at' => \DB::raw('NOW()'), |
|
80 | + 'updated_at' => \DB::raw('NOW()') |
|
81 | + ], |
|
82 | + [ |
|
83 | + 'name' => 'assigngroups', |
|
84 | + 'model' => 'users', |
|
85 | + 'created_at' => \DB::raw('NOW()'), |
|
86 | + 'updated_at' => \DB::raw('NOW()') |
|
87 | + ], |
|
88 | 88 | |
89 | - /** |
|
90 | - * Permissions model permissions. |
|
91 | - */ |
|
92 | - [ |
|
93 | - 'name' => 'find', |
|
94 | - 'model' => 'permissions', |
|
95 | - 'created_at' => \DB::raw('NOW()'), |
|
96 | - 'updated_at' => \DB::raw('NOW()') |
|
97 | - ], |
|
98 | - [ |
|
99 | - 'name' => 'search', |
|
100 | - 'model' => 'permissions', |
|
101 | - 'created_at' => \DB::raw('NOW()'), |
|
102 | - 'updated_at' => \DB::raw('NOW()') |
|
103 | - ], |
|
104 | - [ |
|
105 | - 'name' => 'list', |
|
106 | - 'model' => 'permissions', |
|
107 | - 'created_at' => \DB::raw('NOW()'), |
|
108 | - 'updated_at' => \DB::raw('NOW()') |
|
109 | - ], |
|
110 | - [ |
|
111 | - 'name' => 'findby', |
|
112 | - 'model' => 'permissions', |
|
113 | - 'created_at' => \DB::raw('NOW()'), |
|
114 | - 'updated_at' => \DB::raw('NOW()') |
|
115 | - ], |
|
116 | - [ |
|
117 | - 'name' => 'first', |
|
118 | - 'model' => 'permissions', |
|
119 | - 'created_at' => \DB::raw('NOW()'), |
|
120 | - 'updated_at' => \DB::raw('NOW()') |
|
121 | - ], |
|
122 | - [ |
|
123 | - 'name' => 'paginate', |
|
124 | - 'model' => 'permissions', |
|
125 | - 'created_at' => \DB::raw('NOW()'), |
|
126 | - 'updated_at' => \DB::raw('NOW()') |
|
127 | - ], |
|
128 | - [ |
|
129 | - 'name' => 'paginateby', |
|
130 | - 'model' => 'permissions', |
|
131 | - 'created_at' => \DB::raw('NOW()'), |
|
132 | - 'updated_at' => \DB::raw('NOW()') |
|
133 | - ], |
|
89 | + /** |
|
90 | + * Permissions model permissions. |
|
91 | + */ |
|
92 | + [ |
|
93 | + 'name' => 'find', |
|
94 | + 'model' => 'permissions', |
|
95 | + 'created_at' => \DB::raw('NOW()'), |
|
96 | + 'updated_at' => \DB::raw('NOW()') |
|
97 | + ], |
|
98 | + [ |
|
99 | + 'name' => 'search', |
|
100 | + 'model' => 'permissions', |
|
101 | + 'created_at' => \DB::raw('NOW()'), |
|
102 | + 'updated_at' => \DB::raw('NOW()') |
|
103 | + ], |
|
104 | + [ |
|
105 | + 'name' => 'list', |
|
106 | + 'model' => 'permissions', |
|
107 | + 'created_at' => \DB::raw('NOW()'), |
|
108 | + 'updated_at' => \DB::raw('NOW()') |
|
109 | + ], |
|
110 | + [ |
|
111 | + 'name' => 'findby', |
|
112 | + 'model' => 'permissions', |
|
113 | + 'created_at' => \DB::raw('NOW()'), |
|
114 | + 'updated_at' => \DB::raw('NOW()') |
|
115 | + ], |
|
116 | + [ |
|
117 | + 'name' => 'first', |
|
118 | + 'model' => 'permissions', |
|
119 | + 'created_at' => \DB::raw('NOW()'), |
|
120 | + 'updated_at' => \DB::raw('NOW()') |
|
121 | + ], |
|
122 | + [ |
|
123 | + 'name' => 'paginate', |
|
124 | + 'model' => 'permissions', |
|
125 | + 'created_at' => \DB::raw('NOW()'), |
|
126 | + 'updated_at' => \DB::raw('NOW()') |
|
127 | + ], |
|
128 | + [ |
|
129 | + 'name' => 'paginateby', |
|
130 | + 'model' => 'permissions', |
|
131 | + 'created_at' => \DB::raw('NOW()'), |
|
132 | + 'updated_at' => \DB::raw('NOW()') |
|
133 | + ], |
|
134 | 134 | |
135 | - /** |
|
136 | - * Groups model permissions. |
|
137 | - */ |
|
138 | - [ |
|
139 | - 'name' => 'save', |
|
140 | - 'model' => 'groups', |
|
141 | - 'created_at' => \DB::raw('NOW()'), |
|
142 | - 'updated_at' => \DB::raw('NOW()') |
|
143 | - ], |
|
144 | - [ |
|
145 | - 'name' => 'delete', |
|
146 | - 'model' => 'groups', |
|
147 | - 'created_at' => \DB::raw('NOW()'), |
|
148 | - 'updated_at' => \DB::raw('NOW()') |
|
149 | - ], |
|
150 | - [ |
|
151 | - 'name' => 'find', |
|
152 | - 'model' => 'groups', |
|
153 | - 'created_at' => \DB::raw('NOW()'), |
|
154 | - 'updated_at' => \DB::raw('NOW()') |
|
155 | - ], |
|
156 | - [ |
|
157 | - 'name' => 'search', |
|
158 | - 'model' => 'groups', |
|
159 | - 'created_at' => \DB::raw('NOW()'), |
|
160 | - 'updated_at' => \DB::raw('NOW()') |
|
161 | - ], |
|
162 | - [ |
|
163 | - 'name' => 'list', |
|
164 | - 'model' => 'groups', |
|
165 | - 'created_at' => \DB::raw('NOW()'), |
|
166 | - 'updated_at' => \DB::raw('NOW()') |
|
167 | - ], |
|
168 | - [ |
|
169 | - 'name' => 'findby', |
|
170 | - 'model' => 'groups', |
|
171 | - 'created_at' => \DB::raw('NOW()'), |
|
172 | - 'updated_at' => \DB::raw('NOW()') |
|
173 | - ], |
|
174 | - [ |
|
175 | - 'name' => 'first', |
|
176 | - 'model' => 'groups', |
|
177 | - 'created_at' => \DB::raw('NOW()'), |
|
178 | - 'updated_at' => \DB::raw('NOW()') |
|
179 | - ], |
|
180 | - [ |
|
181 | - 'name' => 'paginate', |
|
182 | - 'model' => 'groups', |
|
183 | - 'created_at' => \DB::raw('NOW()'), |
|
184 | - 'updated_at' => \DB::raw('NOW()') |
|
185 | - ], |
|
186 | - [ |
|
187 | - 'name' => 'paginateby', |
|
188 | - 'model' => 'groups', |
|
189 | - 'created_at' => \DB::raw('NOW()'), |
|
190 | - 'updated_at' => \DB::raw('NOW()') |
|
191 | - ], |
|
192 | - [ |
|
193 | - 'name' => 'assignpermissions', |
|
194 | - 'model' => 'groups', |
|
195 | - 'created_at' => \DB::raw('NOW()'), |
|
196 | - 'updated_at' => \DB::raw('NOW()') |
|
197 | - ], |
|
198 | - ] |
|
199 | - ); |
|
135 | + /** |
|
136 | + * Groups model permissions. |
|
137 | + */ |
|
138 | + [ |
|
139 | + 'name' => 'save', |
|
140 | + 'model' => 'groups', |
|
141 | + 'created_at' => \DB::raw('NOW()'), |
|
142 | + 'updated_at' => \DB::raw('NOW()') |
|
143 | + ], |
|
144 | + [ |
|
145 | + 'name' => 'delete', |
|
146 | + 'model' => 'groups', |
|
147 | + 'created_at' => \DB::raw('NOW()'), |
|
148 | + 'updated_at' => \DB::raw('NOW()') |
|
149 | + ], |
|
150 | + [ |
|
151 | + 'name' => 'find', |
|
152 | + 'model' => 'groups', |
|
153 | + 'created_at' => \DB::raw('NOW()'), |
|
154 | + 'updated_at' => \DB::raw('NOW()') |
|
155 | + ], |
|
156 | + [ |
|
157 | + 'name' => 'search', |
|
158 | + 'model' => 'groups', |
|
159 | + 'created_at' => \DB::raw('NOW()'), |
|
160 | + 'updated_at' => \DB::raw('NOW()') |
|
161 | + ], |
|
162 | + [ |
|
163 | + 'name' => 'list', |
|
164 | + 'model' => 'groups', |
|
165 | + 'created_at' => \DB::raw('NOW()'), |
|
166 | + 'updated_at' => \DB::raw('NOW()') |
|
167 | + ], |
|
168 | + [ |
|
169 | + 'name' => 'findby', |
|
170 | + 'model' => 'groups', |
|
171 | + 'created_at' => \DB::raw('NOW()'), |
|
172 | + 'updated_at' => \DB::raw('NOW()') |
|
173 | + ], |
|
174 | + [ |
|
175 | + 'name' => 'first', |
|
176 | + 'model' => 'groups', |
|
177 | + 'created_at' => \DB::raw('NOW()'), |
|
178 | + 'updated_at' => \DB::raw('NOW()') |
|
179 | + ], |
|
180 | + [ |
|
181 | + 'name' => 'paginate', |
|
182 | + 'model' => 'groups', |
|
183 | + 'created_at' => \DB::raw('NOW()'), |
|
184 | + 'updated_at' => \DB::raw('NOW()') |
|
185 | + ], |
|
186 | + [ |
|
187 | + 'name' => 'paginateby', |
|
188 | + 'model' => 'groups', |
|
189 | + 'created_at' => \DB::raw('NOW()'), |
|
190 | + 'updated_at' => \DB::raw('NOW()') |
|
191 | + ], |
|
192 | + [ |
|
193 | + 'name' => 'assignpermissions', |
|
194 | + 'model' => 'groups', |
|
195 | + 'created_at' => \DB::raw('NOW()'), |
|
196 | + 'updated_at' => \DB::raw('NOW()') |
|
197 | + ], |
|
198 | + ] |
|
199 | + ); |
|
200 | 200 | |
201 | 201 | /** |
202 | 202 | * Delete previous data. |
@@ -224,29 +224,29 @@ discard block |
||
224 | 224 | * Create Default users. |
225 | 225 | */ |
226 | 226 | $adminUserId = DB::table('users')->insertGetId( |
227 | - [ |
|
227 | + [ |
|
228 | 228 | 'email' => '[email protected]', |
229 | 229 | 'password' => bcrypt('123456'), |
230 | 230 | 'created_at' => \DB::raw('NOW()'), |
231 | 231 | 'updated_at' => \DB::raw('NOW()') |
232 | 232 | ] |
233 | - ); |
|
233 | + ); |
|
234 | 234 | |
235 | 235 | /** |
236 | 236 | * Assign users to groups. |
237 | 237 | */ |
238 | 238 | DB::table('users_groups')->insert( |
239 | - [ |
|
240 | - [ |
|
239 | + [ |
|
240 | + [ |
|
241 | 241 | 'user_id' => $adminUserId, |
242 | 242 | 'group_id' => $adminGroupId, |
243 | 243 | 'created_at' => \DB::raw('NOW()'), |
244 | 244 | 'updated_at' => \DB::raw('NOW()') |
245 | - ] |
|
246 | - ] |
|
247 | - ); |
|
245 | + ] |
|
246 | + ] |
|
247 | + ); |
|
248 | 248 | |
249 | - /** |
|
249 | + /** |
|
250 | 250 | * Assign the permissions to the admin group. |
251 | 251 | */ |
252 | 252 | $permissionIds = DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->select('id')->lists('id'); |