@@ -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 = \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 = \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 | } |
@@ -61,6 +61,6 @@ |
||
61 | 61 | $user->groups()->attach($group_ids); |
62 | 62 | }); |
63 | 63 | |
64 | - return \Core::users()->find($user_id); |
|
64 | + return \Core::users()->find($user_id); |
|
65 | 65 | } |
66 | 66 | } |
@@ -29,6 +29,6 @@ |
||
29 | 29 | $group->permissions()->attach($permission_ids); |
30 | 30 | }); |
31 | 31 | |
32 | - return \Core::groups()->find($group_id); |
|
32 | + return \Core::groups()->find($group_id); |
|
33 | 33 | } |
34 | 34 | } |
@@ -8,35 +8,35 @@ |
||
8 | 8 | |
9 | 9 | class GroupsController 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 = 'groups'; |
|
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 = 'groups'; |
|
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|string|max:100|unique:groups,name,{id}' |
|
25 | - ]; |
|
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|string|max:100|unique:groups,name,{id}' |
|
25 | + ]; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Handle an assign permissions to group request. |
|
29 | - * |
|
30 | - * @param \Illuminate\Http\Request $request |
|
31 | - * @return \Illuminate\Http\Response |
|
32 | - */ |
|
33 | - public function postAssignpermissions(Request $request) |
|
34 | - { |
|
35 | - $this->validate($request, [ |
|
36 | - 'permission_ids' => 'required|exists:permissions,id', |
|
37 | - 'group_id' => 'required|exists:groups,id' |
|
38 | - ]); |
|
27 | + /** |
|
28 | + * Handle an assign permissions to group request. |
|
29 | + * |
|
30 | + * @param \Illuminate\Http\Request $request |
|
31 | + * @return \Illuminate\Http\Response |
|
32 | + */ |
|
33 | + public function postAssignpermissions(Request $request) |
|
34 | + { |
|
35 | + $this->validate($request, [ |
|
36 | + 'permission_ids' => 'required|exists:permissions,id', |
|
37 | + 'group_id' => 'required|exists:groups,id' |
|
38 | + ]); |
|
39 | 39 | |
40 | - return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
41 | - } |
|
40 | + return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
41 | + } |
|
42 | 42 | } |
@@ -7,10 +7,10 @@ |
||
7 | 7 | |
8 | 8 | class PermissionsController 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 = 'permissions'; |
|
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 = 'permissions'; |
|
16 | 16 | } |
@@ -13,17 +13,17 @@ |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('users', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('first_name',100)->nullable(); |
|
18 | - $table->string('last_name',100)->nullable(); |
|
19 | - $table->string('user_name',100)->nullable(); |
|
20 | - $table->text('address')->nullable(); |
|
21 | - $table->string('email')->unique(); |
|
22 | - $table->string('password', 60); |
|
23 | - $table->softDeletes(); |
|
24 | - $table->rememberToken(); |
|
25 | - $table->timestamps(); |
|
26 | - }); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('first_name',100)->nullable(); |
|
18 | + $table->string('last_name',100)->nullable(); |
|
19 | + $table->string('user_name',100)->nullable(); |
|
20 | + $table->text('address')->nullable(); |
|
21 | + $table->string('email')->unique(); |
|
22 | + $table->string('password', 60); |
|
23 | + $table->softDeletes(); |
|
24 | + $table->rememberToken(); |
|
25 | + $table->timestamps(); |
|
26 | + }); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -12,21 +12,21 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('permissions', function (Blueprint $table) { |
|
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100); |
|
18 | - $table->string('model',100); |
|
19 | - $table->softDeletes(); |
|
20 | - $table->timestamps(); |
|
21 | - $table->unique(array('name', 'model')); |
|
22 | - }); |
|
23 | - Schema::create('groups_permissions', function (Blueprint $table) { |
|
24 | - $table->increments('id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->integer('permission_id'); |
|
27 | - $table->softDeletes(); |
|
28 | - $table->timestamps(); |
|
29 | - }); |
|
15 | + Schema::create('permissions', function (Blueprint $table) { |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100); |
|
18 | + $table->string('model',100); |
|
19 | + $table->softDeletes(); |
|
20 | + $table->timestamps(); |
|
21 | + $table->unique(array('name', 'model')); |
|
22 | + }); |
|
23 | + Schema::create('groups_permissions', function (Blueprint $table) { |
|
24 | + $table->increments('id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->integer('permission_id'); |
|
27 | + $table->softDeletes(); |
|
28 | + $table->timestamps(); |
|
29 | + }); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -13,19 +13,19 @@ |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('groups', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100)->unique(); |
|
18 | - $table->softDeletes(); |
|
19 | - $table->timestamps(); |
|
20 | - }); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100)->unique(); |
|
18 | + $table->softDeletes(); |
|
19 | + $table->timestamps(); |
|
20 | + }); |
|
21 | 21 | |
22 | - Schema::create('users_groups', function (Blueprint $table) { |
|
23 | - $table->increments('id'); |
|
24 | - $table->integer('user_id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->softDeletes(); |
|
27 | - $table->timestamps(); |
|
28 | - }); |
|
22 | + Schema::create('users_groups', function (Blueprint $table) { |
|
23 | + $table->increments('id'); |
|
24 | + $table->integer('user_id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->softDeletes(); |
|
27 | + $table->timestamps(); |
|
28 | + }); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -4,13 +4,13 @@ |
||
4 | 4 | { |
5 | 5 | /** |
6 | 6 | * Construct the repository class name based on |
7 | - * the method name called, search in the |
|
8 | - * given namespaces for the class and |
|
9 | - * return an instance. |
|
10 | - * |
|
11 | - * @param string $name the called method name |
|
12 | - * @param array $arguments the method arguments |
|
13 | - * @return object |
|
14 | - */ |
|
7 | + * the method name called, search in the |
|
8 | + * given namespaces for the class and |
|
9 | + * return an instance. |
|
10 | + * |
|
11 | + * @param string $name the called method name |
|
12 | + * @param array $arguments the method arguments |
|
13 | + * @return object |
|
14 | + */ |
|
15 | 15 | public function __call($name, $arguments); |
16 | 16 | } |
17 | 17 | \ No newline at end of file |