@@ -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 | } |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ApiSkeletonServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Perform post-registration booting of services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->publishes([ |
|
| 17 | - __DIR__.'/Exceptions' => app_path('Exceptions'), |
|
| 18 | - __DIR__.'/Modules' => app_path('Modules'), |
|
| 19 | - __DIR__.'/notifications' => app_path('notifications'), |
|
| 20 | - __DIR__.'/Kernel.php' => app_path('Http/Kernel.php'), |
|
| 9 | + /** |
|
| 10 | + * Perform post-registration booting of services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->publishes([ |
|
| 17 | + __DIR__.'/Exceptions' => app_path('Exceptions'), |
|
| 18 | + __DIR__.'/Modules' => app_path('Modules'), |
|
| 19 | + __DIR__.'/notifications' => app_path('notifications'), |
|
| 20 | + __DIR__.'/Kernel.php' => app_path('Http/Kernel.php'), |
|
| 21 | 21 | |
| 22 | - ]); |
|
| 22 | + ]); |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Register any package services. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function register() |
|
| 32 | - { |
|
| 33 | - // |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Register any package services. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function register() |
|
| 32 | + { |
|
| 33 | + // |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -5,47 +5,47 @@ |
||
| 5 | 5 | |
| 6 | 6 | class AclGroup extends Model{ |
| 7 | 7 | |
| 8 | - use SoftDeletes; |
|
| 9 | - protected $table = 'groups'; |
|
| 10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | - protected $hidden = ['deleted_at']; |
|
| 12 | - protected $guarded = ['id']; |
|
| 13 | - protected $fillable = ['name']; |
|
| 14 | - |
|
| 15 | - public function getCreatedAtAttribute($value) |
|
| 16 | - { |
|
| 17 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function getUpdatedAtAttribute($value) |
|
| 21 | - { |
|
| 22 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function getDeletedAtAttribute($value) |
|
| 26 | - { |
|
| 27 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function users() |
|
| 31 | - { |
|
| 32 | - return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function permissions() |
|
| 36 | - { |
|
| 37 | - return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public static function boot() |
|
| 41 | - { |
|
| 42 | - parent::boot(); |
|
| 43 | - |
|
| 44 | - AclGroup::deleting(function($group) |
|
| 45 | - { |
|
| 46 | - \DB::table('groups_permissions') |
|
| 47 | - ->where('group_id', $group->id) |
|
| 48 | - ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 49 | - }); |
|
| 50 | - } |
|
| 8 | + use SoftDeletes; |
|
| 9 | + protected $table = 'groups'; |
|
| 10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | + protected $hidden = ['deleted_at']; |
|
| 12 | + protected $guarded = ['id']; |
|
| 13 | + protected $fillable = ['name']; |
|
| 14 | + |
|
| 15 | + public function getCreatedAtAttribute($value) |
|
| 16 | + { |
|
| 17 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function getUpdatedAtAttribute($value) |
|
| 21 | + { |
|
| 22 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function getDeletedAtAttribute($value) |
|
| 26 | + { |
|
| 27 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function users() |
|
| 31 | + { |
|
| 32 | + return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function permissions() |
|
| 36 | + { |
|
| 37 | + return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public static function boot() |
|
| 41 | + { |
|
| 42 | + parent::boot(); |
|
| 43 | + |
|
| 44 | + AclGroup::deleting(function($group) |
|
| 45 | + { |
|
| 46 | + \DB::table('groups_permissions') |
|
| 47 | + ->where('group_id', $group->id) |
|
| 48 | + ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 49 | + }); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -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 | /** |