@@ -5,41 +5,41 @@ |
||
| 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\V1\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\V1\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 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclGroupObserver')); |
|
| 44 | - } |
|
| 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\V1\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\V1\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 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclGroupObserver')); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 5 | 5 | |
| 6 | -class AclGroup extends Model{ |
|
| 6 | +class AclGroup extends Model { |
|
| 7 | 7 | |
| 8 | 8 | use SoftDeletes; |
| 9 | 9 | protected $table = 'groups'; |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function users() |
| 31 | 31 | { |
| 32 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 32 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclUser', 'users_groups', 'group_id', 'user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function permissions() |
| 36 | 36 | { |
| 37 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 37 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclPermission', 'groups_permissions', 'group_id', 'permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public static function boot() |
@@ -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 | /** |
@@ -12,14 +12,14 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('groups', function (Blueprint $table) { |
|
| 15 | + Schema::create('groups', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('name',100)->unique(); |
|
| 17 | + $table->string('name', 100)->unique(); |
|
| 18 | 18 | $table->softDeletes(); |
| 19 | 19 | $table->timestamps(); |
| 20 | 20 | }); |
| 21 | 21 | |
| 22 | - Schema::create('users_groups', function (Blueprint $table) { |
|
| 22 | + Schema::create('users_groups', function(Blueprint $table) { |
|
| 23 | 23 | $table->increments('id'); |
| 24 | 24 | $table->integer('user_id'); |
| 25 | 25 | $table->integer('group_id'); |
@@ -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'); |
@@ -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 | /** |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('permissions', function (Blueprint $table) { |
|
| 15 | + Schema::create('permissions', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('name',100); |
|
| 18 | - $table->string('model',100); |
|
| 17 | + $table->string('name', 100); |
|
| 18 | + $table->string('model', 100); |
|
| 19 | 19 | $table->softDeletes(); |
| 20 | 20 | $table->timestamps(); |
| 21 | 21 | $table->unique(array('name', 'model')); |
| 22 | 22 | }); |
| 23 | - Schema::create('groups_permissions', function (Blueprint $table) { |
|
| 23 | + Schema::create('groups_permissions', function(Blueprint $table) { |
|
| 24 | 24 | $table->increments('id'); |
| 25 | 25 | $table->integer('group_id'); |
| 26 | 26 | $table->integer('permission_id'); |
@@ -5,51 +5,51 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class AclUserObserver { |
| 7 | 7 | |
| 8 | - public function saving($model) |
|
| 9 | - { |
|
| 10 | - // |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - public function saved($model) |
|
| 14 | - { |
|
| 15 | - // |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function creating($model) |
|
| 19 | - { |
|
| 20 | - // |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function created($model) |
|
| 24 | - { |
|
| 25 | - // |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function updating($model) |
|
| 29 | - { |
|
| 30 | - // |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function updated($model) |
|
| 34 | - { |
|
| 35 | - // |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Soft delete the associated groups and logs to the deleted user. |
|
| 40 | - * |
|
| 41 | - * @param object $model the delted model. |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function deleting($model) |
|
| 45 | - { |
|
| 46 | - \DB::table('users_groups')->where('user_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 47 | - $model->logs()->delete(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function deleted($model) |
|
| 51 | - { |
|
| 52 | - // |
|
| 53 | - } |
|
| 8 | + public function saving($model) |
|
| 9 | + { |
|
| 10 | + // |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + public function saved($model) |
|
| 14 | + { |
|
| 15 | + // |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function creating($model) |
|
| 19 | + { |
|
| 20 | + // |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function created($model) |
|
| 24 | + { |
|
| 25 | + // |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function updating($model) |
|
| 29 | + { |
|
| 30 | + // |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function updated($model) |
|
| 34 | + { |
|
| 35 | + // |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Soft delete the associated groups and logs to the deleted user. |
|
| 40 | + * |
|
| 41 | + * @param object $model the delted model. |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function deleting($model) |
|
| 45 | + { |
|
| 46 | + \DB::table('users_groups')->where('user_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 47 | + $model->logs()->delete(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function deleted($model) |
|
| 51 | + { |
|
| 52 | + // |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -5,50 +5,50 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class AclGroupObserver { |
| 7 | 7 | |
| 8 | - public function saving($model) |
|
| 9 | - { |
|
| 10 | - // |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - public function saved($model) |
|
| 14 | - { |
|
| 15 | - // |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function creating($model) |
|
| 19 | - { |
|
| 20 | - // |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function created($model) |
|
| 24 | - { |
|
| 25 | - // |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function updating($model) |
|
| 29 | - { |
|
| 30 | - // |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function updated($model) |
|
| 34 | - { |
|
| 35 | - // |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Soft delete the associated permissions to the deleted group. |
|
| 40 | - * |
|
| 41 | - * @param object $model the delted model. |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function deleting($model) |
|
| 45 | - { |
|
| 46 | - \DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function deleted($model) |
|
| 50 | - { |
|
| 51 | - // |
|
| 52 | - } |
|
| 8 | + public function saving($model) |
|
| 9 | + { |
|
| 10 | + // |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + public function saved($model) |
|
| 14 | + { |
|
| 15 | + // |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function creating($model) |
|
| 19 | + { |
|
| 20 | + // |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function created($model) |
|
| 24 | + { |
|
| 25 | + // |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function updating($model) |
|
| 29 | + { |
|
| 30 | + // |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function updated($model) |
|
| 34 | + { |
|
| 35 | + // |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Soft delete the associated permissions to the deleted group. |
|
| 40 | + * |
|
| 41 | + * @param object $model the delted model. |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function deleting($model) |
|
| 45 | + { |
|
| 46 | + \DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function deleted($model) |
|
| 50 | + { |
|
| 51 | + // |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -5,50 +5,50 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class AclPermissionObserver { |
| 7 | 7 | |
| 8 | - public function saving($model) |
|
| 9 | - { |
|
| 10 | - // |
|
| 11 | - } |
|
| 12 | - |
|
| 13 | - public function saved($model) |
|
| 14 | - { |
|
| 15 | - // |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - public function creating($model) |
|
| 19 | - { |
|
| 20 | - // |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function created($model) |
|
| 24 | - { |
|
| 25 | - // |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function updating($model) |
|
| 29 | - { |
|
| 30 | - // |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function updated($model) |
|
| 34 | - { |
|
| 35 | - // |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Soft delete the associated groups to the deleted permission. |
|
| 40 | - * |
|
| 41 | - * @param object $model the delted model. |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function deleting($model) |
|
| 45 | - { |
|
| 46 | - \DB::table('groups_permissions')->where('permission_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function deleted($model) |
|
| 50 | - { |
|
| 51 | - // |
|
| 52 | - } |
|
| 8 | + public function saving($model) |
|
| 9 | + { |
|
| 10 | + // |
|
| 11 | + } |
|
| 12 | + |
|
| 13 | + public function saved($model) |
|
| 14 | + { |
|
| 15 | + // |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + public function creating($model) |
|
| 19 | + { |
|
| 20 | + // |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function created($model) |
|
| 24 | + { |
|
| 25 | + // |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function updating($model) |
|
| 29 | + { |
|
| 30 | + // |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function updated($model) |
|
| 34 | + { |
|
| 35 | + // |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Soft delete the associated groups to the deleted permission. |
|
| 40 | + * |
|
| 41 | + * @param object $model the delted model. |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function deleting($model) |
|
| 45 | + { |
|
| 46 | + \DB::table('groups_permissions')->where('permission_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function deleted($model) |
|
| 50 | + { |
|
| 51 | + // |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -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 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | public function assignPermissions($group_id, $permission_ids) |
| 25 | 25 | { |
| 26 | - \DB::transaction(function () use ($group_id, $permission_ids) { |
|
| 26 | + \DB::transaction(function() use ($group_id, $permission_ids) { |
|
| 27 | 27 | $group = \Core::groups()->find($group_id); |
| 28 | 28 | $group->permissions()->detach(); |
| 29 | 29 | $group->permissions()->attach($permission_ids); |
@@ -75,12 +75,10 @@ |
||
| 75 | 75 | if ($this->isBlocked($credentials['email'])) |
| 76 | 76 | { |
| 77 | 77 | \ErrorHandler::userIsBlocked(); |
| 78 | - } |
|
| 79 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
| 78 | + } else if ($token = \JWTAuth::attempt($credentials)) |
|
| 80 | 79 | { |
| 81 | 80 | return $token; |
| 82 | - } |
|
| 83 | - else |
|
| 81 | + } else |
|
| 84 | 82 | { |
| 85 | 83 | \ErrorHandler::loginFailed(); |
| 86 | 84 | } |
@@ -202,7 +202,7 @@ |
||
| 202 | 202 | * Reset the given user's password. |
| 203 | 203 | * |
| 204 | 204 | * @param array $credentials |
| 205 | - * @return integer |
|
| 205 | + * @return false|null |
|
| 206 | 206 | */ |
| 207 | 207 | public function resetPassword($credentials) |
| 208 | 208 | { |
@@ -4,232 +4,232 @@ |
||
| 4 | 4 | |
| 5 | 5 | class UserRepository extends AbstractRepository |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Return the model full namespace. |
|
| 9 | - * |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - protected function getModel() |
|
| 13 | - { |
|
| 14 | - return 'App\Modules\V1\Acl\AclUser'; |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * Check if the logged in user or the given user |
|
| 19 | - * has the given permissions on the given model. |
|
| 20 | - * |
|
| 21 | - * @param string $nameOfPermission |
|
| 22 | - * @param string $model |
|
| 23 | - * @param boolean $user |
|
| 24 | - * @return boolean |
|
| 25 | - */ |
|
| 26 | - public function can($nameOfPermission, $model, $user = false ) |
|
| 27 | - { |
|
| 28 | - $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
|
| 29 | - $permissions = []; |
|
| 30 | - \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 31 | - $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
|
| 32 | - }); |
|
| 7 | + /** |
|
| 8 | + * Return the model full namespace. |
|
| 9 | + * |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + protected function getModel() |
|
| 13 | + { |
|
| 14 | + return 'App\Modules\V1\Acl\AclUser'; |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * Check if the logged in user or the given user |
|
| 19 | + * has the given permissions on the given model. |
|
| 20 | + * |
|
| 21 | + * @param string $nameOfPermission |
|
| 22 | + * @param string $model |
|
| 23 | + * @param boolean $user |
|
| 24 | + * @return boolean |
|
| 25 | + */ |
|
| 26 | + public function can($nameOfPermission, $model, $user = false ) |
|
| 27 | + { |
|
| 28 | + $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
|
| 29 | + $permissions = []; |
|
| 30 | + \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 31 | + $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
|
| 32 | + }); |
|
| 33 | 33 | |
| 34 | - return in_array($nameOfPermission, $permissions); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Check if the logged in user has the given group. |
|
| 39 | - * |
|
| 40 | - * @param string $groupName |
|
| 41 | - * @return boolean |
|
| 42 | - */ |
|
| 43 | - public function hasGroup($groupName) |
|
| 44 | - { |
|
| 45 | - $groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups; |
|
| 46 | - return $groups->lists('name')->search($groupName, true) === false ? false : true; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Assign the given group ids to the given user. |
|
| 51 | - * |
|
| 52 | - * @param integer $user_id |
|
| 53 | - * @param array $group_ids |
|
| 54 | - * @return object |
|
| 55 | - */ |
|
| 56 | - public function assignGroups($user_id, $group_ids) |
|
| 57 | - { |
|
| 58 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 59 | - $user = \Core::users()->find($user_id); |
|
| 60 | - $user->groups()->detach(); |
|
| 61 | - $user->groups()->attach($group_ids); |
|
| 62 | - }); |
|
| 63 | - |
|
| 64 | - return \Core::users()->find($user_id); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Handle a login request to the application. |
|
| 69 | - * |
|
| 70 | - * @param array $credentials |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function login($credentials) |
|
| 74 | - { |
|
| 75 | - if ($this->isBlocked($credentials['email'])) |
|
| 76 | - { |
|
| 77 | - \ErrorHandler::userIsBlocked(); |
|
| 78 | - } |
|
| 79 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
| 80 | - { |
|
| 81 | - return $token; |
|
| 82 | - } |
|
| 83 | - else |
|
| 84 | - { |
|
| 85 | - \ErrorHandler::loginFailed(); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Handle a registration request. |
|
| 91 | - * |
|
| 92 | - * @param array $credentials |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function register($credentials) |
|
| 96 | - { |
|
| 97 | - return \JWTAuth::fromUser(\Core::users()->model->create($credentials)); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Logout the user. |
|
| 102 | - * |
|
| 103 | - * @return boolean |
|
| 104 | - */ |
|
| 105 | - public function logout() |
|
| 106 | - { |
|
| 107 | - return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Block the user. |
|
| 112 | - * |
|
| 113 | - * @param integer $user_id |
|
| 114 | - * @return object |
|
| 115 | - */ |
|
| 116 | - public function block($user_id) |
|
| 117 | - { |
|
| 118 | - if ( ! $this->hasGroup('Admin')) |
|
| 119 | - { |
|
| 120 | - \ErrorHandler::noPermissions(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $user = \Core::users()->find($user_id); |
|
| 124 | - $user->blocked = 1; |
|
| 125 | - $user->save(); |
|
| 34 | + return in_array($nameOfPermission, $permissions); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Check if the logged in user has the given group. |
|
| 39 | + * |
|
| 40 | + * @param string $groupName |
|
| 41 | + * @return boolean |
|
| 42 | + */ |
|
| 43 | + public function hasGroup($groupName) |
|
| 44 | + { |
|
| 45 | + $groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups; |
|
| 46 | + return $groups->lists('name')->search($groupName, true) === false ? false : true; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Assign the given group ids to the given user. |
|
| 51 | + * |
|
| 52 | + * @param integer $user_id |
|
| 53 | + * @param array $group_ids |
|
| 54 | + * @return object |
|
| 55 | + */ |
|
| 56 | + public function assignGroups($user_id, $group_ids) |
|
| 57 | + { |
|
| 58 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 59 | + $user = \Core::users()->find($user_id); |
|
| 60 | + $user->groups()->detach(); |
|
| 61 | + $user->groups()->attach($group_ids); |
|
| 62 | + }); |
|
| 63 | + |
|
| 64 | + return \Core::users()->find($user_id); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Handle a login request to the application. |
|
| 69 | + * |
|
| 70 | + * @param array $credentials |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function login($credentials) |
|
| 74 | + { |
|
| 75 | + if ($this->isBlocked($credentials['email'])) |
|
| 76 | + { |
|
| 77 | + \ErrorHandler::userIsBlocked(); |
|
| 78 | + } |
|
| 79 | + else if ($token = \JWTAuth::attempt($credentials)) |
|
| 80 | + { |
|
| 81 | + return $token; |
|
| 82 | + } |
|
| 83 | + else |
|
| 84 | + { |
|
| 85 | + \ErrorHandler::loginFailed(); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Handle a registration request. |
|
| 91 | + * |
|
| 92 | + * @param array $credentials |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function register($credentials) |
|
| 96 | + { |
|
| 97 | + return \JWTAuth::fromUser(\Core::users()->model->create($credentials)); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Logout the user. |
|
| 102 | + * |
|
| 103 | + * @return boolean |
|
| 104 | + */ |
|
| 105 | + public function logout() |
|
| 106 | + { |
|
| 107 | + return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Block the user. |
|
| 112 | + * |
|
| 113 | + * @param integer $user_id |
|
| 114 | + * @return object |
|
| 115 | + */ |
|
| 116 | + public function block($user_id) |
|
| 117 | + { |
|
| 118 | + if ( ! $this->hasGroup('Admin')) |
|
| 119 | + { |
|
| 120 | + \ErrorHandler::noPermissions(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $user = \Core::users()->find($user_id); |
|
| 124 | + $user->blocked = 1; |
|
| 125 | + $user->save(); |
|
| 126 | 126 | |
| 127 | - return $user; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Unblock the user. |
|
| 132 | - * |
|
| 133 | - * @param integer $user_id |
|
| 134 | - * @return object |
|
| 135 | - */ |
|
| 136 | - public function unblock($user_id) |
|
| 137 | - { |
|
| 138 | - if ( ! $this->hasGroup('Admin')) |
|
| 139 | - { |
|
| 140 | - \ErrorHandler::noPermissions(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $user = \Core::users()->find($user_id); |
|
| 144 | - $user->blocked = 0; |
|
| 145 | - $user->save(); |
|
| 146 | - |
|
| 147 | - return $user; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Check if the user blocked or not. |
|
| 152 | - * |
|
| 153 | - * @param string $email |
|
| 154 | - * @return boolean |
|
| 155 | - */ |
|
| 156 | - public function isBlocked($email) |
|
| 157 | - { |
|
| 158 | - $user = \Core::users()->first(['email' => $email]); |
|
| 159 | - if ( ! $user) |
|
| 160 | - { |
|
| 161 | - \ErrorHandler::notFound('email or password'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $user->blocked; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Handle the editing of the user profile. |
|
| 169 | - * |
|
| 170 | - * @param array $profile |
|
| 171 | - * @return object |
|
| 172 | - */ |
|
| 173 | - public function editProfile($profile) |
|
| 174 | - { |
|
| 175 | - unset($profile['email']); |
|
| 176 | - unset($profile['password']); |
|
| 177 | - $profile['id'] = \JWTAuth::parseToken()->authenticate()->id; |
|
| 127 | + return $user; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Unblock the user. |
|
| 132 | + * |
|
| 133 | + * @param integer $user_id |
|
| 134 | + * @return object |
|
| 135 | + */ |
|
| 136 | + public function unblock($user_id) |
|
| 137 | + { |
|
| 138 | + if ( ! $this->hasGroup('Admin')) |
|
| 139 | + { |
|
| 140 | + \ErrorHandler::noPermissions(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $user = \Core::users()->find($user_id); |
|
| 144 | + $user->blocked = 0; |
|
| 145 | + $user->save(); |
|
| 146 | + |
|
| 147 | + return $user; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Check if the user blocked or not. |
|
| 152 | + * |
|
| 153 | + * @param string $email |
|
| 154 | + * @return boolean |
|
| 155 | + */ |
|
| 156 | + public function isBlocked($email) |
|
| 157 | + { |
|
| 158 | + $user = \Core::users()->first(['email' => $email]); |
|
| 159 | + if ( ! $user) |
|
| 160 | + { |
|
| 161 | + \ErrorHandler::notFound('email or password'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $user->blocked; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Handle the editing of the user profile. |
|
| 169 | + * |
|
| 170 | + * @param array $profile |
|
| 171 | + * @return object |
|
| 172 | + */ |
|
| 173 | + public function editProfile($profile) |
|
| 174 | + { |
|
| 175 | + unset($profile['email']); |
|
| 176 | + unset($profile['password']); |
|
| 177 | + $profile['id'] = \JWTAuth::parseToken()->authenticate()->id; |
|
| 178 | 178 | |
| 179 | - return $this->save($profile); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Send a reset link to the given user. |
|
| 184 | - * |
|
| 185 | - * @param string $email |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - public function sendReset($email) |
|
| 189 | - { |
|
| 190 | - $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
| 191 | - $message->subject('Your Password Reset Link'); |
|
| 192 | - }); |
|
| 193 | - |
|
| 194 | - switch ($response) |
|
| 195 | - { |
|
| 196 | - case \Password::INVALID_USER: |
|
| 197 | - \ErrorHandler::notFound('email'); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Reset the given user's password. |
|
| 203 | - * |
|
| 204 | - * @param array $credentials |
|
| 205 | - * @return integer |
|
| 206 | - */ |
|
| 207 | - public function resetPassword($credentials) |
|
| 208 | - { |
|
| 209 | - $token = false; |
|
| 210 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
| 211 | - $user->password = $password; |
|
| 212 | - $user->save(); |
|
| 213 | - |
|
| 214 | - $token = \JWTAuth::fromUser($user); |
|
| 215 | - }); |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - switch ($response) { |
|
| 219 | - case \Password::PASSWORD_RESET: |
|
| 220 | - return $token; |
|
| 179 | + return $this->save($profile); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Send a reset link to the given user. |
|
| 184 | + * |
|
| 185 | + * @param string $email |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + public function sendReset($email) |
|
| 189 | + { |
|
| 190 | + $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
| 191 | + $message->subject('Your Password Reset Link'); |
|
| 192 | + }); |
|
| 193 | + |
|
| 194 | + switch ($response) |
|
| 195 | + { |
|
| 196 | + case \Password::INVALID_USER: |
|
| 197 | + \ErrorHandler::notFound('email'); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Reset the given user's password. |
|
| 203 | + * |
|
| 204 | + * @param array $credentials |
|
| 205 | + * @return integer |
|
| 206 | + */ |
|
| 207 | + public function resetPassword($credentials) |
|
| 208 | + { |
|
| 209 | + $token = false; |
|
| 210 | + $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
| 211 | + $user->password = $password; |
|
| 212 | + $user->save(); |
|
| 213 | + |
|
| 214 | + $token = \JWTAuth::fromUser($user); |
|
| 215 | + }); |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + switch ($response) { |
|
| 219 | + case \Password::PASSWORD_RESET: |
|
| 220 | + return $token; |
|
| 221 | 221 | |
| 222 | - case \Password::INVALID_TOKEN: |
|
| 223 | - \ErrorHandler::invalidResetToken('token'); |
|
| 222 | + case \Password::INVALID_TOKEN: |
|
| 223 | + \ErrorHandler::invalidResetToken('token'); |
|
| 224 | 224 | |
| 225 | - case \Password::INVALID_PASSWORD: |
|
| 226 | - \ErrorHandler::invalidResetPassword('email'); |
|
| 225 | + case \Password::INVALID_PASSWORD: |
|
| 226 | + \ErrorHandler::invalidResetPassword('email'); |
|
| 227 | 227 | |
| 228 | - case \Password::INVALID_USER: |
|
| 229 | - \ErrorHandler::notFound('user'); |
|
| 228 | + case \Password::INVALID_USER: |
|
| 229 | + \ErrorHandler::notFound('user'); |
|
| 230 | 230 | |
| 231 | - default: |
|
| 232 | - \ErrorHandler::generalError(); |
|
| 233 | - } |
|
| 234 | - } |
|
| 231 | + default: |
|
| 232 | + \ErrorHandler::generalError(); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | * @param boolean $user |
| 24 | 24 | * @return boolean |
| 25 | 25 | */ |
| 26 | - public function can($nameOfPermission, $model, $user = false ) |
|
| 26 | + public function can($nameOfPermission, $model, $user = false) |
|
| 27 | 27 | { |
| 28 | 28 | $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
| 29 | 29 | $permissions = []; |
| 30 | - \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 30 | + \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function($permission) use (&$permissions, $model){ |
|
| 31 | 31 | $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
| 32 | 32 | }); |
| 33 | 33 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function assignGroups($user_id, $group_ids) |
| 57 | 57 | { |
| 58 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 58 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
| 59 | 59 | $user = \Core::users()->find($user_id); |
| 60 | 60 | $user->groups()->detach(); |
| 61 | 61 | $user->groups()->attach($group_ids); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function sendReset($email) |
| 189 | 189 | { |
| 190 | - $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
| 190 | + $response = \Password::sendResetLink($email, function(\Illuminate\Mail\Message $message) { |
|
| 191 | 191 | $message->subject('Your Password Reset Link'); |
| 192 | 192 | }); |
| 193 | 193 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function resetPassword($credentials) |
| 208 | 208 | { |
| 209 | 209 | $token = false; |
| 210 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
| 210 | + $response = \Password::reset($credentials, function($user, $password) use (&$token) { |
|
| 211 | 211 | $user->password = $password; |
| 212 | 212 | $user->save(); |
| 213 | 213 | |