@@ -12,7 +12,7 @@ |
||
12 | 12 | * to preform actions like (add, edit ... etc). |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $model = 'notifications'; |
|
15 | + protected $model = 'notifications'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Set the notification notified to true. |
@@ -8,30 +8,30 @@ |
||
8 | 8 | class NotificationsController extends BaseApiController |
9 | 9 | { |
10 | 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 = 'notifications'; |
|
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 = 'notifications'; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Set the notification notified to true. |
|
19 | - * |
|
20 | - * @param integer $id |
|
21 | - * @return \Illuminate\Http\Response |
|
22 | - */ |
|
23 | - public function notified($id) |
|
24 | - { |
|
25 | - return \Response::json(\Core::notifications()->notified($id), 200); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Set the notification notified to true. |
|
19 | + * |
|
20 | + * @param integer $id |
|
21 | + * @return \Illuminate\Http\Response |
|
22 | + */ |
|
23 | + public function notified($id) |
|
24 | + { |
|
25 | + return \Response::json(\Core::notifications()->notified($id), 200); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Set the notification notified to all. |
|
30 | - * |
|
31 | - * @return \Illuminate\Http\Response |
|
32 | - */ |
|
33 | - public function notifyall() |
|
34 | - { |
|
35 | - return \Response::json(\Core::notifications()->notifyAll(), 200); |
|
36 | - } |
|
28 | + /** |
|
29 | + * Set the notification notified to all. |
|
30 | + * |
|
31 | + * @return \Illuminate\Http\Response |
|
32 | + */ |
|
33 | + public function notifyall() |
|
34 | + { |
|
35 | + return \Response::json(\Core::notifications()->notifyAll(), 200); |
|
36 | + } |
|
37 | 37 | } |
@@ -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() |
@@ -5,42 +5,42 @@ |
||
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 | - public $searchable = ['name']; |
|
15 | - |
|
16 | - public function getCreatedAtAttribute($value) |
|
17 | - { |
|
18 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | - } |
|
20 | - |
|
21 | - public function getUpdatedAtAttribute($value) |
|
22 | - { |
|
23 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | - } |
|
25 | - |
|
26 | - public function getDeletedAtAttribute($value) |
|
27 | - { |
|
28 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | - } |
|
30 | - |
|
31 | - public function users() |
|
32 | - { |
|
33 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
34 | - } |
|
35 | - |
|
36 | - public function permissions() |
|
37 | - { |
|
38 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
39 | - } |
|
40 | - |
|
41 | - public static function boot() |
|
42 | - { |
|
43 | - parent::boot(); |
|
44 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclGroupObserver')); |
|
45 | - } |
|
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 | + public $searchable = ['name']; |
|
15 | + |
|
16 | + public function getCreatedAtAttribute($value) |
|
17 | + { |
|
18 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | + } |
|
20 | + |
|
21 | + public function getUpdatedAtAttribute($value) |
|
22 | + { |
|
23 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | + } |
|
25 | + |
|
26 | + public function getDeletedAtAttribute($value) |
|
27 | + { |
|
28 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | + } |
|
30 | + |
|
31 | + public function users() |
|
32 | + { |
|
33 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
34 | + } |
|
35 | + |
|
36 | + public function permissions() |
|
37 | + { |
|
38 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
39 | + } |
|
40 | + |
|
41 | + public static function boot() |
|
42 | + { |
|
43 | + parent::boot(); |
|
44 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclGroupObserver')); |
|
45 | + } |
|
46 | 46 | } |
@@ -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,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'); |
@@ -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); |
@@ -29,6 +29,6 @@ |
||
29 | 29 | $group->permissions()->attach($permission_ids); |
30 | 30 | }); |
31 | 31 | |
32 | - return $this->find($group_id); |
|
32 | + return $this->find($group_id); |
|
33 | 33 | } |
34 | 34 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | public function groups() |
31 | 31 | { |
32 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
32 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'groups_permissions', 'permission_id', 'group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public static function boot() |
@@ -5,37 +5,37 @@ |
||
5 | 5 | |
6 | 6 | class AclPermission extends Model { |
7 | 7 | |
8 | - use SoftDeletes; |
|
9 | - protected $table = 'permissions'; |
|
10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | - protected $hidden = ['deleted_at']; |
|
12 | - protected $guarded = ['id']; |
|
13 | - protected $fillable = ['name', 'model']; |
|
14 | - public $searchable = ['name', 'model']; |
|
8 | + use SoftDeletes; |
|
9 | + protected $table = 'permissions'; |
|
10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | + protected $hidden = ['deleted_at']; |
|
12 | + protected $guarded = ['id']; |
|
13 | + protected $fillable = ['name', 'model']; |
|
14 | + public $searchable = ['name', 'model']; |
|
15 | 15 | |
16 | - public function getCreatedAtAttribute($value) |
|
17 | - { |
|
18 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | - } |
|
16 | + public function getCreatedAtAttribute($value) |
|
17 | + { |
|
18 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function getUpdatedAtAttribute($value) |
|
22 | - { |
|
23 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | - } |
|
21 | + public function getUpdatedAtAttribute($value) |
|
22 | + { |
|
23 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | + } |
|
25 | 25 | |
26 | - public function getDeletedAtAttribute($value) |
|
27 | - { |
|
28 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | - } |
|
26 | + public function getDeletedAtAttribute($value) |
|
27 | + { |
|
28 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | + } |
|
30 | 30 | |
31 | - public function groups() |
|
32 | - { |
|
33 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
34 | - } |
|
31 | + public function groups() |
|
32 | + { |
|
33 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
34 | + } |
|
35 | 35 | |
36 | - public static function boot() |
|
37 | - { |
|
38 | - parent::boot(); |
|
39 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclPermissionObserver')); |
|
40 | - } |
|
36 | + public static function boot() |
|
37 | + { |
|
38 | + parent::boot(); |
|
39 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclPermissionObserver')); |
|
40 | + } |
|
41 | 41 | } |
@@ -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,14 +13,14 @@ |
||
13 | 13 | * to preform actions like (add, edit ... etc). |
14 | 14 | * @var string |
15 | 15 | */ |
16 | - protected $model = 'groups'; |
|
16 | + protected $model = 'groups'; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The validations rules used by the base api controller |
20 | 20 | * to check before add. |
21 | 21 | * @var array |
22 | 22 | */ |
23 | - protected $validationRules = [ |
|
23 | + protected $validationRules = [ |
|
24 | 24 | 'name' => 'required|string|max:100|unique:groups,name,{id}' |
25 | 25 | ]; |
26 | 26 |
@@ -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 assignpermissions(Request $request) |
|
34 | - { |
|
35 | - $this->validate($request, [ |
|
36 | - 'permission_ids' => 'required|exists:permissions,id', |
|
37 | - 'group_id' => 'required|array|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 assignpermissions(Request $request) |
|
34 | + { |
|
35 | + $this->validate($request, [ |
|
36 | + 'permission_ids' => 'required|exists:permissions,id', |
|
37 | + 'group_id' => 'required|array|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 | } |
@@ -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 | { |
@@ -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 | - $this->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
30 | + $this->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 = $this->find($user_id); |
60 | 60 | $user->groups()->detach(); |
61 | 61 | $user->groups()->attach($group_ids); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $view->with(['url' => $url]); |
223 | 223 | }); |
224 | 224 | |
225 | - $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
225 | + $response = \Password::sendResetLink($email, function(\Illuminate\Mail\Message $message) { |
|
226 | 226 | $message->subject('Your Password Reset Link'); |
227 | 227 | }); |
228 | 228 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | public function resetPassword($credentials) |
243 | 243 | { |
244 | 244 | $token = false; |
245 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
245 | + $response = \Password::reset($credentials, function($user, $password) use (&$token) { |
|
246 | 246 | $user->password = bcrypt($password); |
247 | 247 | $user->save(); |
248 | 248 |
@@ -76,24 +76,19 @@ discard block |
||
76 | 76 | if ( ! $user = $this->first(['email' => $credentials['email']])) |
77 | 77 | { |
78 | 78 | \ErrorHandler::loginFailed(); |
79 | - } |
|
80 | - else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) |
|
79 | + } else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) |
|
81 | 80 | { |
82 | 81 | \ErrorHandler::loginFailed(); |
83 | - } |
|
84 | - else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) |
|
82 | + } else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) |
|
85 | 83 | { |
86 | 84 | \ErrorHandler::loginFailed(); |
87 | - } |
|
88 | - else if ($user->blocked) |
|
85 | + } else if ($user->blocked) |
|
89 | 86 | { |
90 | 87 | \ErrorHandler::userIsBlocked(); |
91 | - } |
|
92 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
88 | + } else if ($token = \JWTAuth::attempt($credentials)) |
|
93 | 89 | { |
94 | 90 | return ['token' => $token]; |
95 | - } |
|
96 | - else |
|
91 | + } else |
|
97 | 92 | { |
98 | 93 | \ErrorHandler::loginFailed(); |
99 | 94 | } |
@@ -118,8 +113,7 @@ discard block |
||
118 | 113 | { |
119 | 114 | $data = ['email' => $user->email, 'password' => '']; |
120 | 115 | return $this->register($data); |
121 | - } |
|
122 | - else |
|
116 | + } else |
|
123 | 117 | { |
124 | 118 | return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
125 | 119 | } |
@@ -161,12 +155,10 @@ discard block |
||
161 | 155 | if ( ! $this->hasGroup('Admin')) |
162 | 156 | { |
163 | 157 | \ErrorHandler::noPermissions(); |
164 | - } |
|
165 | - else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
158 | + } else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
166 | 159 | { |
167 | 160 | \ErrorHandler::noPermissions(); |
168 | - } |
|
169 | - else if ($user->groups->lists('name')->search('Admin', true) !== false) |
|
161 | + } else if ($user->groups->lists('name')->search('Admin', true) !== false) |
|
170 | 162 | { |
171 | 163 | \ErrorHandler::noPermissions(); |
172 | 164 | } |
@@ -4,271 +4,271 @@ |
||
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 | - } |
|
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 | 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 | - $group = \Session::get('group'); |
|
31 | - \Session::set('group', null); |
|
32 | - $this->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
33 | - $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
|
34 | - }); |
|
35 | - \Session::set('group', $group); |
|
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 | + $group = \Session::get('group'); |
|
31 | + \Session::set('group', null); |
|
32 | + $this->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
33 | + $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
|
34 | + }); |
|
35 | + \Session::set('group', $group); |
|
36 | 36 | |
37 | - return in_array($nameOfPermission, $permissions); |
|
38 | - } |
|
37 | + return in_array($nameOfPermission, $permissions); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Check if the logged in user has the given group. |
|
42 | - * |
|
43 | - * @param string $groupName |
|
44 | - * @return boolean |
|
45 | - */ |
|
46 | - public function hasGroup($groupName) |
|
47 | - { |
|
48 | - $groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups; |
|
49 | - return $groups->lists('name')->search($groupName, true) === false ? false : true; |
|
50 | - } |
|
40 | + /** |
|
41 | + * Check if the logged in user has the given group. |
|
42 | + * |
|
43 | + * @param string $groupName |
|
44 | + * @return boolean |
|
45 | + */ |
|
46 | + public function hasGroup($groupName) |
|
47 | + { |
|
48 | + $groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups; |
|
49 | + return $groups->lists('name')->search($groupName, true) === false ? false : true; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Assign the given group ids to the given user. |
|
54 | - * |
|
55 | - * @param integer $user_id |
|
56 | - * @param array $group_ids |
|
57 | - * @return object |
|
58 | - */ |
|
59 | - public function assignGroups($user_id, $group_ids) |
|
60 | - { |
|
61 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
62 | - $user = $this->find($user_id); |
|
63 | - $user->groups()->detach(); |
|
64 | - $user->groups()->attach($group_ids); |
|
65 | - }); |
|
52 | + /** |
|
53 | + * Assign the given group ids to the given user. |
|
54 | + * |
|
55 | + * @param integer $user_id |
|
56 | + * @param array $group_ids |
|
57 | + * @return object |
|
58 | + */ |
|
59 | + public function assignGroups($user_id, $group_ids) |
|
60 | + { |
|
61 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
62 | + $user = $this->find($user_id); |
|
63 | + $user->groups()->detach(); |
|
64 | + $user->groups()->attach($group_ids); |
|
65 | + }); |
|
66 | 66 | |
67 | - return $this->find($user_id); |
|
68 | - } |
|
67 | + return $this->find($user_id); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Handle a login request to the application. |
|
72 | - * |
|
73 | - * @param array $credentials |
|
74 | - * @param boolean $adminLogin |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function login($credentials, $adminLogin = false) |
|
78 | - { |
|
79 | - if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
80 | - { |
|
81 | - \ErrorHandler::loginFailed(); |
|
82 | - } |
|
83 | - else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) |
|
84 | - { |
|
85 | - \ErrorHandler::loginFailed(); |
|
86 | - } |
|
87 | - else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) |
|
88 | - { |
|
89 | - \ErrorHandler::loginFailed(); |
|
90 | - } |
|
91 | - else if ($user->blocked) |
|
92 | - { |
|
93 | - \ErrorHandler::userIsBlocked(); |
|
94 | - } |
|
95 | - else if ($token = \JWTAuth::attempt($credentials)) |
|
96 | - { |
|
97 | - return ['token' => $token]; |
|
98 | - } |
|
99 | - else |
|
100 | - { |
|
101 | - \ErrorHandler::loginFailed(); |
|
102 | - } |
|
103 | - } |
|
70 | + /** |
|
71 | + * Handle a login request to the application. |
|
72 | + * |
|
73 | + * @param array $credentials |
|
74 | + * @param boolean $adminLogin |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function login($credentials, $adminLogin = false) |
|
78 | + { |
|
79 | + if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
80 | + { |
|
81 | + \ErrorHandler::loginFailed(); |
|
82 | + } |
|
83 | + else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) |
|
84 | + { |
|
85 | + \ErrorHandler::loginFailed(); |
|
86 | + } |
|
87 | + else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) |
|
88 | + { |
|
89 | + \ErrorHandler::loginFailed(); |
|
90 | + } |
|
91 | + else if ($user->blocked) |
|
92 | + { |
|
93 | + \ErrorHandler::userIsBlocked(); |
|
94 | + } |
|
95 | + else if ($token = \JWTAuth::attempt($credentials)) |
|
96 | + { |
|
97 | + return ['token' => $token]; |
|
98 | + } |
|
99 | + else |
|
100 | + { |
|
101 | + \ErrorHandler::loginFailed(); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Handle a social login request of the none admin to the application. |
|
107 | - * |
|
108 | - * @param array $credentials |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function loginSocial($credentials) |
|
112 | - { |
|
113 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
114 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
105 | + /** |
|
106 | + * Handle a social login request of the none admin to the application. |
|
107 | + * |
|
108 | + * @param array $credentials |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function loginSocial($credentials) |
|
112 | + { |
|
113 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
114 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
115 | 115 | |
116 | - if ( ! $user->email) |
|
117 | - { |
|
118 | - \ErrorHandler::noSocialEmail(); |
|
119 | - } |
|
116 | + if ( ! $user->email) |
|
117 | + { |
|
118 | + \ErrorHandler::noSocialEmail(); |
|
119 | + } |
|
120 | 120 | |
121 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
122 | - { |
|
123 | - $data = ['email' => $user->email, 'password' => '']; |
|
124 | - return $this->register($data); |
|
125 | - } |
|
126 | - else |
|
127 | - { |
|
128 | - return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
|
129 | - } |
|
130 | - } |
|
121 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
122 | + { |
|
123 | + $data = ['email' => $user->email, 'password' => '']; |
|
124 | + return $this->register($data); |
|
125 | + } |
|
126 | + else |
|
127 | + { |
|
128 | + return $this->login(['email' => $registeredUser->email, 'password' => ''], false); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Handle a registration request. |
|
134 | - * |
|
135 | - * @param array $credentials |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function register($credentials) |
|
139 | - { |
|
140 | - return ['token' => \JWTAuth::fromUser($this->model->create($credentials))]; |
|
141 | - } |
|
132 | + /** |
|
133 | + * Handle a registration request. |
|
134 | + * |
|
135 | + * @param array $credentials |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function register($credentials) |
|
139 | + { |
|
140 | + return ['token' => \JWTAuth::fromUser($this->model->create($credentials))]; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Logout the user. |
|
145 | - * |
|
146 | - * @return boolean |
|
147 | - */ |
|
148 | - public function logout() |
|
149 | - { |
|
150 | - return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
151 | - } |
|
143 | + /** |
|
144 | + * Logout the user. |
|
145 | + * |
|
146 | + * @return boolean |
|
147 | + */ |
|
148 | + public function logout() |
|
149 | + { |
|
150 | + return \JWTAuth::invalidate(\JWTAuth::getToken()); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Block the user. |
|
155 | - * |
|
156 | - * @param integer $user_id |
|
157 | - * @return object |
|
158 | - */ |
|
159 | - public function block($user_id) |
|
160 | - { |
|
161 | - if ( ! $user = $this->find($user_id)) |
|
162 | - { |
|
163 | - \ErrorHandler::notFound('user'); |
|
164 | - } |
|
165 | - if ( ! $this->hasGroup('Admin')) |
|
166 | - { |
|
167 | - \ErrorHandler::noPermissions(); |
|
168 | - } |
|
169 | - else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
170 | - { |
|
171 | - \ErrorHandler::noPermissions(); |
|
172 | - } |
|
173 | - else if ($user->groups->lists('name')->search('Admin', true) !== false) |
|
174 | - { |
|
175 | - \ErrorHandler::noPermissions(); |
|
176 | - } |
|
153 | + /** |
|
154 | + * Block the user. |
|
155 | + * |
|
156 | + * @param integer $user_id |
|
157 | + * @return object |
|
158 | + */ |
|
159 | + public function block($user_id) |
|
160 | + { |
|
161 | + if ( ! $user = $this->find($user_id)) |
|
162 | + { |
|
163 | + \ErrorHandler::notFound('user'); |
|
164 | + } |
|
165 | + if ( ! $this->hasGroup('Admin')) |
|
166 | + { |
|
167 | + \ErrorHandler::noPermissions(); |
|
168 | + } |
|
169 | + else if (\JWTAuth::parseToken()->authenticate()->id == $user_id) |
|
170 | + { |
|
171 | + \ErrorHandler::noPermissions(); |
|
172 | + } |
|
173 | + else if ($user->groups->lists('name')->search('Admin', true) !== false) |
|
174 | + { |
|
175 | + \ErrorHandler::noPermissions(); |
|
176 | + } |
|
177 | 177 | |
178 | - $user->blocked = 1; |
|
179 | - $user->save(); |
|
178 | + $user->blocked = 1; |
|
179 | + $user->save(); |
|
180 | 180 | |
181 | - return $user; |
|
182 | - } |
|
181 | + return $user; |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Unblock the user. |
|
186 | - * |
|
187 | - * @param integer $user_id |
|
188 | - * @return object |
|
189 | - */ |
|
190 | - public function unblock($user_id) |
|
191 | - { |
|
192 | - if ( ! $this->hasGroup('Admin')) |
|
193 | - { |
|
194 | - \ErrorHandler::noPermissions(); |
|
195 | - } |
|
184 | + /** |
|
185 | + * Unblock the user. |
|
186 | + * |
|
187 | + * @param integer $user_id |
|
188 | + * @return object |
|
189 | + */ |
|
190 | + public function unblock($user_id) |
|
191 | + { |
|
192 | + if ( ! $this->hasGroup('Admin')) |
|
193 | + { |
|
194 | + \ErrorHandler::noPermissions(); |
|
195 | + } |
|
196 | 196 | |
197 | - $user = $this->find($user_id); |
|
198 | - $user->blocked = 0; |
|
199 | - $user->save(); |
|
197 | + $user = $this->find($user_id); |
|
198 | + $user->blocked = 0; |
|
199 | + $user->save(); |
|
200 | 200 | |
201 | - return $user; |
|
202 | - } |
|
201 | + return $user; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Send a reset link to the given user. |
|
206 | - * |
|
207 | - * @param string $url |
|
208 | - * @param string $email |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function sendReset($email, $url) |
|
212 | - { |
|
213 | - view()->composer('auth.emails.password', function($view) use ($url) { |
|
214 | - $view->with(['url' => $url]); |
|
215 | - }); |
|
204 | + /** |
|
205 | + * Send a reset link to the given user. |
|
206 | + * |
|
207 | + * @param string $url |
|
208 | + * @param string $email |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function sendReset($email, $url) |
|
212 | + { |
|
213 | + view()->composer('auth.emails.password', function($view) use ($url) { |
|
214 | + $view->with(['url' => $url]); |
|
215 | + }); |
|
216 | 216 | |
217 | - $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
218 | - $message->subject('Your Password Reset Link'); |
|
219 | - }); |
|
217 | + $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
218 | + $message->subject('Your Password Reset Link'); |
|
219 | + }); |
|
220 | 220 | |
221 | - switch ($response) |
|
222 | - { |
|
223 | - case \Password::INVALID_USER: |
|
224 | - \ErrorHandler::notFound('email'); |
|
225 | - } |
|
226 | - } |
|
221 | + switch ($response) |
|
222 | + { |
|
223 | + case \Password::INVALID_USER: |
|
224 | + \ErrorHandler::notFound('email'); |
|
225 | + } |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Reset the given user's password. |
|
230 | - * |
|
231 | - * @param array $credentials |
|
232 | - * @return integer |
|
233 | - */ |
|
234 | - public function resetPassword($credentials) |
|
235 | - { |
|
236 | - $token = false; |
|
237 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
238 | - $user->password = bcrypt($password); |
|
239 | - $user->save(); |
|
228 | + /** |
|
229 | + * Reset the given user's password. |
|
230 | + * |
|
231 | + * @param array $credentials |
|
232 | + * @return integer |
|
233 | + */ |
|
234 | + public function resetPassword($credentials) |
|
235 | + { |
|
236 | + $token = false; |
|
237 | + $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
238 | + $user->password = bcrypt($password); |
|
239 | + $user->save(); |
|
240 | 240 | |
241 | - $token = \JWTAuth::fromUser($user); |
|
242 | - }); |
|
241 | + $token = \JWTAuth::fromUser($user); |
|
242 | + }); |
|
243 | 243 | |
244 | 244 | |
245 | - switch ($response) { |
|
246 | - case \Password::PASSWORD_RESET: |
|
247 | - return $token; |
|
245 | + switch ($response) { |
|
246 | + case \Password::PASSWORD_RESET: |
|
247 | + return $token; |
|
248 | 248 | |
249 | - case \Password::INVALID_TOKEN: |
|
250 | - \ErrorHandler::invalidResetToken('token'); |
|
249 | + case \Password::INVALID_TOKEN: |
|
250 | + \ErrorHandler::invalidResetToken('token'); |
|
251 | 251 | |
252 | - case \Password::INVALID_PASSWORD: |
|
253 | - \ErrorHandler::invalidResetPassword('email'); |
|
252 | + case \Password::INVALID_PASSWORD: |
|
253 | + \ErrorHandler::invalidResetPassword('email'); |
|
254 | 254 | |
255 | - case \Password::INVALID_USER: |
|
256 | - \ErrorHandler::notFound('user'); |
|
255 | + case \Password::INVALID_USER: |
|
256 | + \ErrorHandler::notFound('user'); |
|
257 | 257 | |
258 | - default: |
|
259 | - \ErrorHandler::generalError(); |
|
260 | - } |
|
261 | - } |
|
258 | + default: |
|
259 | + \ErrorHandler::generalError(); |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Refresh the expired login token. |
|
265 | - * |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public function refreshtoken() |
|
269 | - { |
|
270 | - $token = \JWTAuth::parseToken()->refresh(); |
|
263 | + /** |
|
264 | + * Refresh the expired login token. |
|
265 | + * |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public function refreshtoken() |
|
269 | + { |
|
270 | + $token = \JWTAuth::parseToken()->refresh(); |
|
271 | 271 | |
272 | - return ['token' => $token]; |
|
273 | - } |
|
272 | + return ['token' => $token]; |
|
273 | + } |
|
274 | 274 | } |