@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$factory->define(App\Modules\V1\Notifications\PushNotificationDevice::class, function (Faker\Generator $faker) { |
|
3 | +$factory->define(App\Modules\V1\Notifications\PushNotificationDevice::class, function(Faker\Generator $faker) { |
|
4 | 4 | return [ |
5 | 5 | 'device_token' => $faker->sha1(), |
6 | 6 | 'user_id' => $faker->randomDigitNotNull(), |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | $factory->define(App\Modules\V1\Notifications\PushNotificationDevice::class, function (Faker\Generator $faker) { |
4 | - return [ |
|
4 | + return [ |
|
5 | 5 | 'device_token' => $faker->sha1(), |
6 | 6 | 'user_id' => $faker->randomDigitNotNull(), |
7 | 7 | 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
8 | 8 | 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
9 | - ]; |
|
9 | + ]; |
|
10 | 10 | }); |
11 | 11 | \ No newline at end of file |
@@ -20,7 +20,7 @@ |
||
20 | 20 | $table->unique(array('device_token', 'user_id')); |
21 | 21 | $table->softDeletes(); |
22 | 22 | $table->timestamps(); |
23 | - }); |
|
23 | + }); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('push_notifications_devices', function (Blueprint $table) { |
|
15 | + Schema::create('push_notifications_devices', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | 17 | $table->string('device_token'); |
18 | 18 | $table->integer('user_id'); |
@@ -6,33 +6,33 @@ |
||
6 | 6 | |
7 | 7 | class CreateJobsTable extends Migration |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the migrations. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function up() |
|
15 | - { |
|
16 | - Schema::create('jobs', function (Blueprint $table) { |
|
17 | - $table->bigIncrements('id'); |
|
18 | - $table->string('queue'); |
|
19 | - $table->longText('payload'); |
|
20 | - $table->tinyInteger('attempts')->unsigned(); |
|
21 | - $table->unsignedInteger('reserved_at')->nullable(); |
|
22 | - $table->unsignedInteger('available_at'); |
|
23 | - $table->unsignedInteger('created_at'); |
|
9 | + /** |
|
10 | + * Run the migrations. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function up() |
|
15 | + { |
|
16 | + Schema::create('jobs', function (Blueprint $table) { |
|
17 | + $table->bigIncrements('id'); |
|
18 | + $table->string('queue'); |
|
19 | + $table->longText('payload'); |
|
20 | + $table->tinyInteger('attempts')->unsigned(); |
|
21 | + $table->unsignedInteger('reserved_at')->nullable(); |
|
22 | + $table->unsignedInteger('available_at'); |
|
23 | + $table->unsignedInteger('created_at'); |
|
24 | 24 | |
25 | - $table->index(['queue', 'reserved_at']); |
|
26 | - }); |
|
27 | - } |
|
25 | + $table->index(['queue', 'reserved_at']); |
|
26 | + }); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Reverse the migrations. |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function down() |
|
35 | - { |
|
36 | - Schema::dropIfExists('jobs'); |
|
37 | - } |
|
29 | + /** |
|
30 | + * Reverse the migrations. |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function down() |
|
35 | + { |
|
36 | + Schema::dropIfExists('jobs'); |
|
37 | + } |
|
38 | 38 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function up() |
15 | 15 | { |
16 | - Schema::create('jobs', function (Blueprint $table) { |
|
16 | + Schema::create('jobs', function(Blueprint $table) { |
|
17 | 17 | $table->bigIncrements('id'); |
18 | 18 | $table->string('queue'); |
19 | 19 | $table->longText('payload'); |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | use App\User; |
4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
5 | -use Illuminate\Notifications\Notifiable; |
|
6 | 5 | use Laravel\Passport\HasApiTokens; |
7 | 6 | |
8 | 7 | class AclUser extends User { |
@@ -7,89 +7,89 @@ |
||
7 | 7 | |
8 | 8 | class AclUser extends User { |
9 | 9 | |
10 | - use SoftDeletes, HasApiTokens; |
|
11 | - protected $table = 'users'; |
|
12 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
13 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
14 | - protected $guarded = ['id']; |
|
15 | - protected $fillable = ['name', 'email', 'password']; |
|
16 | - public $searchable = ['name', 'email']; |
|
10 | + use SoftDeletes, HasApiTokens; |
|
11 | + protected $table = 'users'; |
|
12 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
13 | + protected $hidden = ['password', 'remember_token','deleted_at']; |
|
14 | + protected $guarded = ['id']; |
|
15 | + protected $fillable = ['name', 'email', 'password']; |
|
16 | + public $searchable = ['name', 'email']; |
|
17 | 17 | |
18 | - public function getCreatedAtAttribute($value) |
|
19 | - { |
|
20 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | - } |
|
18 | + public function getCreatedAtAttribute($value) |
|
19 | + { |
|
20 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function getUpdatedAtAttribute($value) |
|
24 | - { |
|
25 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26 | - } |
|
23 | + public function getUpdatedAtAttribute($value) |
|
24 | + { |
|
25 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26 | + } |
|
27 | 27 | |
28 | - public function getDeletedAtAttribute($value) |
|
29 | - { |
|
30 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31 | - } |
|
28 | + public function getDeletedAtAttribute($value) |
|
29 | + { |
|
30 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Encrypt the password attribute before |
|
35 | - * saving it in the storage. |
|
36 | - * |
|
37 | - * @param string $value |
|
38 | - */ |
|
39 | - public function setPasswordAttribute($value) |
|
40 | - { |
|
41 | - $this->attributes['password'] = bcrypt($value); |
|
42 | - } |
|
33 | + /** |
|
34 | + * Encrypt the password attribute before |
|
35 | + * saving it in the storage. |
|
36 | + * |
|
37 | + * @param string $value |
|
38 | + */ |
|
39 | + public function setPasswordAttribute($value) |
|
40 | + { |
|
41 | + $this->attributes['password'] = bcrypt($value); |
|
42 | + } |
|
43 | 43 | |
44 | - public function groups() |
|
45 | - { |
|
46 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47 | - } |
|
44 | + public function groups() |
|
45 | + { |
|
46 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Return fcm device tokens related to the user. |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function routeNotificationForFCM() |
|
54 | - { |
|
55 | - $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
56 | - $tokens = []; |
|
49 | + /** |
|
50 | + * Return fcm device tokens related to the user. |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function routeNotificationForFCM() |
|
54 | + { |
|
55 | + $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
56 | + $tokens = []; |
|
57 | 57 | |
58 | - foreach ($devices as $device) |
|
59 | - { |
|
60 | - $accessToken = decrypt($device->access_token); |
|
58 | + foreach ($devices as $device) |
|
59 | + { |
|
60 | + $accessToken = decrypt($device->access_token); |
|
61 | 61 | |
62 | - try |
|
63 | - { |
|
64 | - if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
65 | - { |
|
66 | - continue; |
|
67 | - } |
|
62 | + try |
|
63 | + { |
|
64 | + if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
65 | + { |
|
66 | + continue; |
|
67 | + } |
|
68 | 68 | |
69 | - $tokens[] = $device->device_token; |
|
70 | - } |
|
71 | - catch (\Exception $e) |
|
72 | - { |
|
73 | - $device->forceDelete(); |
|
74 | - } |
|
75 | - } |
|
69 | + $tokens[] = $device->device_token; |
|
70 | + } |
|
71 | + catch (\Exception $e) |
|
72 | + { |
|
73 | + $device->forceDelete(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - return $tokens; |
|
78 | - } |
|
77 | + return $tokens; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * The channels the user receives notification broadcasts on. |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function receivesBroadcastNotificationsOn() |
|
86 | - { |
|
87 | - return 'users.' . $this->id; |
|
88 | - } |
|
80 | + /** |
|
81 | + * The channels the user receives notification broadcasts on. |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function receivesBroadcastNotificationsOn() |
|
86 | + { |
|
87 | + return 'users.' . $this->id; |
|
88 | + } |
|
89 | 89 | |
90 | - public static function boot() |
|
91 | - { |
|
92 | - parent::boot(); |
|
93 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
94 | - } |
|
90 | + public static function boot() |
|
91 | + { |
|
92 | + parent::boot(); |
|
93 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
94 | + } |
|
95 | 95 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | use SoftDeletes, HasApiTokens; |
11 | 11 | protected $table = 'users'; |
12 | 12 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
13 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
13 | + protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
14 | 14 | protected $guarded = ['id']; |
15 | 15 | protected $fillable = ['name', 'email', 'password']; |
16 | 16 | public $searchable = ['name', 'email']; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function groups() |
45 | 45 | { |
46 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
46 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function receivesBroadcastNotificationsOn() |
86 | 86 | { |
87 | - return 'users.' . $this->id; |
|
87 | + return 'users.'.$this->id; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | public static function boot() |
@@ -67,8 +67,7 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | $tokens[] = $device->device_token; |
70 | - } |
|
71 | - catch (\Exception $e) |
|
70 | + } catch (\Exception $e) |
|
72 | 71 | { |
73 | 72 | $device->forceDelete(); |
74 | 73 | } |
@@ -2,25 +2,25 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * List of error messages used in core module. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'Please login before any action', |
|
9 | - 'invalidRefreshToken' => 'Invalid refresh token', |
|
10 | - 'noPermissions' => 'No permissions', |
|
11 | - 'loginFailed' => 'Wrong mail or password', |
|
12 | - 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | - 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | - 'connectionError' => 'Connection error', |
|
15 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
16 | - 'dbQueryError' => 'Please check the given inputes', |
|
17 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
18 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
19 | - 'userIsBlocked' => 'You have been blocked', |
|
20 | - 'invalidResetToken' => 'Reset password token is invalid', |
|
21 | - 'invalidResetPassword' => 'Reset password is invalid', |
|
22 | - 'invalidOldPassword' => 'Old password is invalid', |
|
23 | - 'notFound' => 'The requested :replace not found', |
|
24 | - 'generalError' => 'Something went wrong', |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'Please login before any action', |
|
9 | + 'invalidRefreshToken' => 'Invalid refresh token', |
|
10 | + 'noPermissions' => 'No permissions', |
|
11 | + 'loginFailed' => 'Wrong mail or password', |
|
12 | + 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
13 | + 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
14 | + 'connectionError' => 'Connection error', |
|
15 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
16 | + 'dbQueryError' => 'Please check the given inputes', |
|
17 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
18 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
19 | + 'userIsBlocked' => 'You have been blocked', |
|
20 | + 'invalidResetToken' => 'Reset password token is invalid', |
|
21 | + 'invalidResetPassword' => 'Reset password is invalid', |
|
22 | + 'invalidOldPassword' => 'Old password is invalid', |
|
23 | + 'notFound' => 'The requested :replace not found', |
|
24 | + 'generalError' => 'Something went wrong', |
|
25 | 25 | |
26 | 26 | ]; |
27 | 27 | \ No newline at end of file |
@@ -2,25 +2,25 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * List of error messages used in core module. |
|
7 | - */ |
|
8 | - 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | - 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
10 | - 'noPermissions' => 'لا توجد صلاحية', |
|
11 | - 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | - 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | - 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | - 'connectionError' => 'خطأ في الاتصال', |
|
15 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
16 | - 'dbQueryError' => 'خطا في البيانات', |
|
17 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
18 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
19 | - 'userIsBlocked' => 'لقد تم حظرك', |
|
20 | - 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
21 | - 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
22 | - 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
23 | - 'notFound' => 'ال :replace المطلوب غير موجود', |
|
24 | - 'generalError' => 'حدث خطا ما', |
|
5 | + /** |
|
6 | + * List of error messages used in core module. |
|
7 | + */ |
|
8 | + 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
9 | + 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
10 | + 'noPermissions' => 'لا توجد صلاحية', |
|
11 | + 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
12 | + 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
13 | + 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
14 | + 'connectionError' => 'خطأ في الاتصال', |
|
15 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
16 | + 'dbQueryError' => 'خطا في البيانات', |
|
17 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
18 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
19 | + 'userIsBlocked' => 'لقد تم حظرك', |
|
20 | + 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
21 | + 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
22 | + 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
23 | + 'notFound' => 'ال :replace المطلوب غير موجود', |
|
24 | + 'generalError' => 'حدث خطا ما', |
|
25 | 25 | |
26 | 26 | ]; |
27 | 27 | \ No newline at end of file |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $user = \Core::users()->find(\Auth::id(), $relations); |
49 | 49 | foreach ($user->groups()->get() as $group) |
50 | 50 | { |
51 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
51 | + $group->permissions->each(function($permission) use (&$permissions){ |
|
52 | 52 | $permissions[$permission->model][$permission->id] = $permission->name; |
53 | 53 | }); |
54 | 54 | } |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | * @param boolean $user |
67 | 67 | * @return boolean |
68 | 68 | */ |
69 | - public function can($nameOfPermission, $model, $user = false ) |
|
69 | + public function can($nameOfPermission, $model, $user = false) |
|
70 | 70 | { |
71 | 71 | $user = $user = $this->find(\Auth::id(), ['groups.permissions']); |
72 | 72 | $permissions = []; |
73 | 73 | |
74 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
74 | + $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){ |
|
75 | 75 | $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
76 | 76 | }); |
77 | 77 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function assignGroups($user_id, $group_ids) |
103 | 103 | { |
104 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
104 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
105 | 105 | $user = $this->find($user_id); |
106 | 106 | $user->groups()->detach(); |
107 | 107 | $user->groups()->attach($group_ids); |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $url = $this->config['resetLink']; |
251 | 251 | $token = \Password::getRepository()->create($user); |
252 | 252 | |
253 | - \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
253 | + \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function($m) use ($user) { |
|
254 | 254 | $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
255 | 255 | }); |
256 | 256 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function resetPassword($credentials) |
265 | 265 | { |
266 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
266 | + $response = \Password::reset($credentials, function($user, $password) { |
|
267 | 267 | $user->password = $password; |
268 | 268 | $user->save(); |
269 | 269 | }); |
@@ -122,16 +122,13 @@ discard block |
||
122 | 122 | if ( ! $user = $this->first(['email' => $credentials['email']])) |
123 | 123 | { |
124 | 124 | \ErrorHandler::loginFailed(); |
125 | - } |
|
126 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
125 | + } else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
127 | 126 | { |
128 | 127 | \ErrorHandler::loginFailed(); |
129 | - } |
|
130 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
128 | + } else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
131 | 129 | { |
132 | 130 | \ErrorHandler::loginFailed(); |
133 | - } |
|
134 | - else if ($user->blocked) |
|
131 | + } else if ($user->blocked) |
|
135 | 132 | { |
136 | 133 | \ErrorHandler::userIsBlocked(); |
137 | 134 | } |
@@ -159,8 +156,7 @@ discard block |
||
159 | 156 | { |
160 | 157 | $data = ['email' => $user->email, 'password' => '']; |
161 | 158 | return $this->register($data); |
162 | - } |
|
163 | - else |
|
159 | + } else |
|
164 | 160 | { |
165 | 161 | if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
166 | 162 | { |
@@ -198,12 +194,10 @@ discard block |
||
198 | 194 | if ( ! $this->hasGroup('Admin')) |
199 | 195 | { |
200 | 196 | \ErrorHandler::noPermissions(); |
201 | - } |
|
202 | - else if (\Auth::id() == $user_id) |
|
197 | + } else if (\Auth::id() == $user_id) |
|
203 | 198 | { |
204 | 199 | \ErrorHandler::noPermissions(); |
205 | - } |
|
206 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
200 | + } else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
207 | 201 | { |
208 | 202 | \ErrorHandler::noPermissions(); |
209 | 203 | } |
@@ -259,7 +259,7 @@ |
||
259 | 259 | * Reset the given user's password. |
260 | 260 | * |
261 | 261 | * @param array $credentials |
262 | - * @return array |
|
262 | + * @return string|null |
|
263 | 263 | */ |
264 | 264 | public function resetPassword($credentials) |
265 | 265 | { |
@@ -7,368 +7,368 @@ |
||
7 | 7 | |
8 | 8 | class UserRepository extends AbstractRepository |
9 | 9 | { |
10 | - /** |
|
11 | - * Return the model full namespace. |
|
12 | - * |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - protected function getModel() |
|
16 | - { |
|
17 | - return 'App\Modules\V1\Acl\AclUser'; |
|
18 | - } |
|
19 | - |
|
20 | - /** |
|
21 | - * The loginProxy implementation. |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $loginProxy; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var The accessTokenRepository implementation. |
|
29 | - */ |
|
30 | - private $accessTokenRepository; |
|
31 | - |
|
32 | - public function __construct(LoginProxy $loginProxy, AccessTokenRepositoryInterface $accessTokenRepository) |
|
33 | - { |
|
34 | - $this->loginProxy = $loginProxy; |
|
35 | - $this->accessTokenRepository = $accessTokenRepository; |
|
36 | - parent::__construct(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Return the logged in user account. |
|
41 | - * |
|
42 | - * @param array $relations |
|
43 | - * @return boolean |
|
44 | - */ |
|
45 | - public function account($relations = []) |
|
46 | - { |
|
47 | - $permissions = []; |
|
48 | - $user = \Core::users()->find(\Auth::id(), $relations); |
|
49 | - foreach ($user->groups()->get() as $group) |
|
50 | - { |
|
51 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
52 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
53 | - }); |
|
54 | - } |
|
55 | - $user->permissions = $permissions; |
|
56 | - |
|
57 | - return $user; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Check if the logged in user or the given user |
|
62 | - * has the given permissions on the given model. |
|
63 | - * |
|
64 | - * @param string $nameOfPermission |
|
65 | - * @param string $model |
|
66 | - * @param boolean $user |
|
67 | - * @return boolean |
|
68 | - */ |
|
69 | - public function can($nameOfPermission, $model, $user = false ) |
|
70 | - { |
|
71 | - $user = $user = $this->find(\Auth::id(), ['groups.permissions']); |
|
72 | - $permissions = []; |
|
73 | - |
|
74 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
75 | - $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
76 | - }); |
|
10 | + /** |
|
11 | + * Return the model full namespace. |
|
12 | + * |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + protected function getModel() |
|
16 | + { |
|
17 | + return 'App\Modules\V1\Acl\AclUser'; |
|
18 | + } |
|
19 | + |
|
20 | + /** |
|
21 | + * The loginProxy implementation. |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $loginProxy; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var The accessTokenRepository implementation. |
|
29 | + */ |
|
30 | + private $accessTokenRepository; |
|
31 | + |
|
32 | + public function __construct(LoginProxy $loginProxy, AccessTokenRepositoryInterface $accessTokenRepository) |
|
33 | + { |
|
34 | + $this->loginProxy = $loginProxy; |
|
35 | + $this->accessTokenRepository = $accessTokenRepository; |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Return the logged in user account. |
|
41 | + * |
|
42 | + * @param array $relations |
|
43 | + * @return boolean |
|
44 | + */ |
|
45 | + public function account($relations = []) |
|
46 | + { |
|
47 | + $permissions = []; |
|
48 | + $user = \Core::users()->find(\Auth::id(), $relations); |
|
49 | + foreach ($user->groups()->get() as $group) |
|
50 | + { |
|
51 | + $group->permissions->each(function ($permission) use (&$permissions){ |
|
52 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
53 | + }); |
|
54 | + } |
|
55 | + $user->permissions = $permissions; |
|
56 | + |
|
57 | + return $user; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Check if the logged in user or the given user |
|
62 | + * has the given permissions on the given model. |
|
63 | + * |
|
64 | + * @param string $nameOfPermission |
|
65 | + * @param string $model |
|
66 | + * @param boolean $user |
|
67 | + * @return boolean |
|
68 | + */ |
|
69 | + public function can($nameOfPermission, $model, $user = false ) |
|
70 | + { |
|
71 | + $user = $user = $this->find(\Auth::id(), ['groups.permissions']); |
|
72 | + $permissions = []; |
|
73 | + |
|
74 | + $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
75 | + $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
76 | + }); |
|
77 | 77 | |
78 | - return in_array($nameOfPermission, $permissions); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Check if the logged in user has the given group. |
|
83 | - * |
|
84 | - * @param string $groupName |
|
85 | - * @param integer $userId |
|
86 | - * @return boolean |
|
87 | - */ |
|
88 | - public function hasGroup($groupName, $userId = false) |
|
89 | - { |
|
90 | - $userId = $userId ?: \Auth::id(); |
|
91 | - $groups = $this->find($userId)->groups; |
|
92 | - return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Assign the given group ids to the given user. |
|
97 | - * |
|
98 | - * @param integer $user_id |
|
99 | - * @param array $group_ids |
|
100 | - * @return object |
|
101 | - */ |
|
102 | - public function assignGroups($user_id, $group_ids) |
|
103 | - { |
|
104 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
105 | - $user = $this->find($user_id); |
|
106 | - $user->groups()->detach(); |
|
107 | - $user->groups()->attach($group_ids); |
|
108 | - }); |
|
109 | - |
|
110 | - return $this->find($user_id); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Handle a login request to the application. |
|
115 | - * |
|
116 | - * @param array $credentials |
|
117 | - * @param boolean $adminLogin |
|
118 | - * @return object |
|
119 | - */ |
|
120 | - public function login($credentials, $adminLogin = false) |
|
121 | - { |
|
122 | - if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
123 | - { |
|
124 | - \ErrorHandler::loginFailed(); |
|
125 | - } |
|
126 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
127 | - { |
|
128 | - \ErrorHandler::loginFailed(); |
|
129 | - } |
|
130 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
131 | - { |
|
132 | - \ErrorHandler::loginFailed(); |
|
133 | - } |
|
134 | - else if ($user->blocked) |
|
135 | - { |
|
136 | - \ErrorHandler::userIsBlocked(); |
|
137 | - } |
|
138 | - |
|
139 | - return $user; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Handle a social login request of the none admin to the application. |
|
144 | - * |
|
145 | - * @param array $credentials |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function loginSocial($credentials) |
|
149 | - { |
|
150 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
151 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
152 | - |
|
153 | - if ( ! $user->email) |
|
154 | - { |
|
155 | - \ErrorHandler::noSocialEmail(); |
|
156 | - } |
|
157 | - |
|
158 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
159 | - { |
|
160 | - $data = ['email' => $user->email, 'password' => '']; |
|
161 | - return $this->register($data); |
|
162 | - } |
|
163 | - else |
|
164 | - { |
|
165 | - if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
166 | - { |
|
167 | - \ErrorHandler::userAlreadyRegistered(); |
|
168 | - } |
|
169 | - |
|
170 | - return $this->loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
171 | - } |
|
172 | - } |
|
78 | + return in_array($nameOfPermission, $permissions); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Check if the logged in user has the given group. |
|
83 | + * |
|
84 | + * @param string $groupName |
|
85 | + * @param integer $userId |
|
86 | + * @return boolean |
|
87 | + */ |
|
88 | + public function hasGroup($groupName, $userId = false) |
|
89 | + { |
|
90 | + $userId = $userId ?: \Auth::id(); |
|
91 | + $groups = $this->find($userId)->groups; |
|
92 | + return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Assign the given group ids to the given user. |
|
97 | + * |
|
98 | + * @param integer $user_id |
|
99 | + * @param array $group_ids |
|
100 | + * @return object |
|
101 | + */ |
|
102 | + public function assignGroups($user_id, $group_ids) |
|
103 | + { |
|
104 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
105 | + $user = $this->find($user_id); |
|
106 | + $user->groups()->detach(); |
|
107 | + $user->groups()->attach($group_ids); |
|
108 | + }); |
|
109 | + |
|
110 | + return $this->find($user_id); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Handle a login request to the application. |
|
115 | + * |
|
116 | + * @param array $credentials |
|
117 | + * @param boolean $adminLogin |
|
118 | + * @return object |
|
119 | + */ |
|
120 | + public function login($credentials, $adminLogin = false) |
|
121 | + { |
|
122 | + if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
123 | + { |
|
124 | + \ErrorHandler::loginFailed(); |
|
125 | + } |
|
126 | + else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
127 | + { |
|
128 | + \ErrorHandler::loginFailed(); |
|
129 | + } |
|
130 | + else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
131 | + { |
|
132 | + \ErrorHandler::loginFailed(); |
|
133 | + } |
|
134 | + else if ($user->blocked) |
|
135 | + { |
|
136 | + \ErrorHandler::userIsBlocked(); |
|
137 | + } |
|
138 | + |
|
139 | + return $user; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Handle a social login request of the none admin to the application. |
|
144 | + * |
|
145 | + * @param array $credentials |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function loginSocial($credentials) |
|
149 | + { |
|
150 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
151 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
152 | + |
|
153 | + if ( ! $user->email) |
|
154 | + { |
|
155 | + \ErrorHandler::noSocialEmail(); |
|
156 | + } |
|
157 | + |
|
158 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
159 | + { |
|
160 | + $data = ['email' => $user->email, 'password' => '']; |
|
161 | + return $this->register($data); |
|
162 | + } |
|
163 | + else |
|
164 | + { |
|
165 | + if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
166 | + { |
|
167 | + \ErrorHandler::userAlreadyRegistered(); |
|
168 | + } |
|
169 | + |
|
170 | + return $this->loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Handle a registration request. |
|
176 | - * |
|
177 | - * @param array $credentials |
|
178 | - * @return array |
|
179 | - */ |
|
180 | - public function register($credentials) |
|
181 | - { |
|
182 | - $this->model->create($credentials); |
|
183 | - return $this->loginProxy->login($credentials, 0); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Block the user. |
|
188 | - * |
|
189 | - * @param integer $user_id |
|
190 | - * @return object |
|
191 | - */ |
|
192 | - public function block($user_id) |
|
193 | - { |
|
194 | - if ( ! $user = $this->find($user_id)) |
|
195 | - { |
|
196 | - \ErrorHandler::notFound('user'); |
|
197 | - } |
|
198 | - if ( ! $this->hasGroup('Admin')) |
|
199 | - { |
|
200 | - \ErrorHandler::noPermissions(); |
|
201 | - } |
|
202 | - else if (\Auth::id() == $user_id) |
|
203 | - { |
|
204 | - \ErrorHandler::noPermissions(); |
|
205 | - } |
|
206 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
207 | - { |
|
208 | - \ErrorHandler::noPermissions(); |
|
209 | - } |
|
210 | - |
|
211 | - $user->blocked = 1; |
|
212 | - $user->save(); |
|
174 | + /** |
|
175 | + * Handle a registration request. |
|
176 | + * |
|
177 | + * @param array $credentials |
|
178 | + * @return array |
|
179 | + */ |
|
180 | + public function register($credentials) |
|
181 | + { |
|
182 | + $this->model->create($credentials); |
|
183 | + return $this->loginProxy->login($credentials, 0); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Block the user. |
|
188 | + * |
|
189 | + * @param integer $user_id |
|
190 | + * @return object |
|
191 | + */ |
|
192 | + public function block($user_id) |
|
193 | + { |
|
194 | + if ( ! $user = $this->find($user_id)) |
|
195 | + { |
|
196 | + \ErrorHandler::notFound('user'); |
|
197 | + } |
|
198 | + if ( ! $this->hasGroup('Admin')) |
|
199 | + { |
|
200 | + \ErrorHandler::noPermissions(); |
|
201 | + } |
|
202 | + else if (\Auth::id() == $user_id) |
|
203 | + { |
|
204 | + \ErrorHandler::noPermissions(); |
|
205 | + } |
|
206 | + else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
207 | + { |
|
208 | + \ErrorHandler::noPermissions(); |
|
209 | + } |
|
210 | + |
|
211 | + $user->blocked = 1; |
|
212 | + $user->save(); |
|
213 | 213 | |
214 | - return $user; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Unblock the user. |
|
219 | - * |
|
220 | - * @param integer $user_id |
|
221 | - * @return object |
|
222 | - */ |
|
223 | - public function unblock($user_id) |
|
224 | - { |
|
225 | - if ( ! $this->hasGroup('Admin')) |
|
226 | - { |
|
227 | - \ErrorHandler::noPermissions(); |
|
228 | - } |
|
229 | - |
|
230 | - $user = $this->find($user_id); |
|
231 | - $user->blocked = 0; |
|
232 | - $user->save(); |
|
233 | - |
|
234 | - return $user; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Send a reset link to the given user. |
|
239 | - * |
|
240 | - * @param string $email |
|
241 | - * @return void |
|
242 | - */ |
|
243 | - public function sendReset($email) |
|
244 | - { |
|
245 | - if ( ! $user = $this->model->where('email', $email)->first()) |
|
246 | - { |
|
247 | - \ErrorHandler::notFound('email'); |
|
248 | - } |
|
249 | - |
|
250 | - $url = $this->config['resetLink']; |
|
251 | - $token = \Password::getRepository()->create($user); |
|
214 | + return $user; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Unblock the user. |
|
219 | + * |
|
220 | + * @param integer $user_id |
|
221 | + * @return object |
|
222 | + */ |
|
223 | + public function unblock($user_id) |
|
224 | + { |
|
225 | + if ( ! $this->hasGroup('Admin')) |
|
226 | + { |
|
227 | + \ErrorHandler::noPermissions(); |
|
228 | + } |
|
229 | + |
|
230 | + $user = $this->find($user_id); |
|
231 | + $user->blocked = 0; |
|
232 | + $user->save(); |
|
233 | + |
|
234 | + return $user; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Send a reset link to the given user. |
|
239 | + * |
|
240 | + * @param string $email |
|
241 | + * @return void |
|
242 | + */ |
|
243 | + public function sendReset($email) |
|
244 | + { |
|
245 | + if ( ! $user = $this->model->where('email', $email)->first()) |
|
246 | + { |
|
247 | + \ErrorHandler::notFound('email'); |
|
248 | + } |
|
249 | + |
|
250 | + $url = $this->config['resetLink']; |
|
251 | + $token = \Password::getRepository()->create($user); |
|
252 | 252 | |
253 | - \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
254 | - $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
255 | - }); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Reset the given user's password. |
|
260 | - * |
|
261 | - * @param array $credentials |
|
262 | - * @return array |
|
263 | - */ |
|
264 | - public function resetPassword($credentials) |
|
265 | - { |
|
266 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
267 | - $user->password = $password; |
|
268 | - $user->save(); |
|
269 | - }); |
|
270 | - |
|
271 | - switch ($response) { |
|
272 | - case \Password::PASSWORD_RESET: |
|
273 | - return 'success'; |
|
253 | + \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
254 | + $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
255 | + }); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Reset the given user's password. |
|
260 | + * |
|
261 | + * @param array $credentials |
|
262 | + * @return array |
|
263 | + */ |
|
264 | + public function resetPassword($credentials) |
|
265 | + { |
|
266 | + $response = \Password::reset($credentials, function ($user, $password) { |
|
267 | + $user->password = $password; |
|
268 | + $user->save(); |
|
269 | + }); |
|
270 | + |
|
271 | + switch ($response) { |
|
272 | + case \Password::PASSWORD_RESET: |
|
273 | + return 'success'; |
|
274 | 274 | |
275 | - case \Password::INVALID_TOKEN: |
|
276 | - \ErrorHandler::invalidResetToken('token'); |
|
277 | - |
|
278 | - case \Password::INVALID_PASSWORD: |
|
279 | - \ErrorHandler::invalidResetPassword('email'); |
|
280 | - |
|
281 | - case \Password::INVALID_USER: |
|
282 | - \ErrorHandler::notFound('user'); |
|
283 | - |
|
284 | - default: |
|
285 | - \ErrorHandler::generalError(); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Change the logged in user password. |
|
291 | - * |
|
292 | - * @param array $credentials |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - public function changePassword($credentials) |
|
296 | - { |
|
297 | - $user = \Auth::user(); |
|
298 | - if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
299 | - { |
|
300 | - \ErrorHandler::invalidOldPassword(); |
|
301 | - } |
|
302 | - |
|
303 | - $user->password = $credentials['password']; |
|
304 | - $user->save(); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Paginate all users in the given group based on the given conditions. |
|
309 | - * |
|
310 | - * @param string $groupName |
|
311 | - * @param array $relations |
|
312 | - * @param integer $perPage |
|
313 | - * @param string $sortBy |
|
314 | - * @param boolean $desc |
|
315 | - * @return \Illuminate\Http\Response |
|
316 | - */ |
|
317 | - public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
318 | - { |
|
319 | - unset($conditions['page']); |
|
320 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
321 | - $sort = $desc ? 'desc' : 'asc'; |
|
322 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
323 | - |
|
324 | - $model->whereHas('groups', function($q) use ($groupName){ |
|
325 | - $q->where('name', $groupName); |
|
326 | - }); |
|
275 | + case \Password::INVALID_TOKEN: |
|
276 | + \ErrorHandler::invalidResetToken('token'); |
|
277 | + |
|
278 | + case \Password::INVALID_PASSWORD: |
|
279 | + \ErrorHandler::invalidResetPassword('email'); |
|
280 | + |
|
281 | + case \Password::INVALID_USER: |
|
282 | + \ErrorHandler::notFound('user'); |
|
283 | + |
|
284 | + default: |
|
285 | + \ErrorHandler::generalError(); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Change the logged in user password. |
|
291 | + * |
|
292 | + * @param array $credentials |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + public function changePassword($credentials) |
|
296 | + { |
|
297 | + $user = \Auth::user(); |
|
298 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
299 | + { |
|
300 | + \ErrorHandler::invalidOldPassword(); |
|
301 | + } |
|
302 | + |
|
303 | + $user->password = $credentials['password']; |
|
304 | + $user->save(); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Paginate all users in the given group based on the given conditions. |
|
309 | + * |
|
310 | + * @param string $groupName |
|
311 | + * @param array $relations |
|
312 | + * @param integer $perPage |
|
313 | + * @param string $sortBy |
|
314 | + * @param boolean $desc |
|
315 | + * @return \Illuminate\Http\Response |
|
316 | + */ |
|
317 | + public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
318 | + { |
|
319 | + unset($conditions['page']); |
|
320 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
321 | + $sort = $desc ? 'desc' : 'asc'; |
|
322 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
323 | + |
|
324 | + $model->whereHas('groups', function($q) use ($groupName){ |
|
325 | + $q->where('name', $groupName); |
|
326 | + }); |
|
327 | 327 | |
328 | 328 | |
329 | - if (count($conditions['conditionValues'])) |
|
330 | - { |
|
331 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
332 | - } |
|
333 | - |
|
334 | - if ($perPage) |
|
335 | - { |
|
336 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
337 | - } |
|
338 | - |
|
339 | - return $model->orderBy($sortBy, $sort)->get(); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Save the given data to the logged in user. |
|
344 | - * |
|
345 | - * @param array $credentials |
|
346 | - * @return object |
|
347 | - */ |
|
348 | - public function saveProfile($credentials) |
|
349 | - { |
|
350 | - $user = \Auth::user(); |
|
351 | - $user->save($credentials); |
|
352 | - |
|
353 | - return $user; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Ensure access token hasn't expired or revoked. |
|
358 | - * |
|
359 | - * @param string $accessToken |
|
360 | - * @return boolean |
|
361 | - */ |
|
362 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
363 | - { |
|
364 | - $data = new ValidationData(); |
|
365 | - $data->setCurrentTime(time()); |
|
366 | - |
|
367 | - if ($accessToken->validate($data) === false || $this->accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
368 | - { |
|
369 | - return true; |
|
370 | - } |
|
371 | - |
|
372 | - return false; |
|
373 | - } |
|
329 | + if (count($conditions['conditionValues'])) |
|
330 | + { |
|
331 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
332 | + } |
|
333 | + |
|
334 | + if ($perPage) |
|
335 | + { |
|
336 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
337 | + } |
|
338 | + |
|
339 | + return $model->orderBy($sortBy, $sort)->get(); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Save the given data to the logged in user. |
|
344 | + * |
|
345 | + * @param array $credentials |
|
346 | + * @return object |
|
347 | + */ |
|
348 | + public function saveProfile($credentials) |
|
349 | + { |
|
350 | + $user = \Auth::user(); |
|
351 | + $user->save($credentials); |
|
352 | + |
|
353 | + return $user; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Ensure access token hasn't expired or revoked. |
|
358 | + * |
|
359 | + * @param string $accessToken |
|
360 | + * @return boolean |
|
361 | + */ |
|
362 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
363 | + { |
|
364 | + $data = new ValidationData(); |
|
365 | + $data->setCurrentTime(time()); |
|
366 | + |
|
367 | + if ($accessToken->validate($data) === false || $this->accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
368 | + { |
|
369 | + return true; |
|
370 | + } |
|
371 | + |
|
372 | + return false; |
|
373 | + } |
|
374 | 374 | } |
@@ -14,27 +14,27 @@ |
||
14 | 14 | return 'App\Modules\V1\Acl\OauthClient'; |
15 | 15 | } |
16 | 16 | |
17 | - /** |
|
18 | - * Revoke the given client. |
|
19 | - * |
|
20 | - * @param integer $clientId |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function revoke($clientId) |
|
24 | - { |
|
25 | - $client = $this->find($clientId); |
|
26 | - $client->tokens()->update(['revoked' => true]); |
|
27 | - $client->forceFill(['revoked' => true])->save(); |
|
28 | - } |
|
17 | + /** |
|
18 | + * Revoke the given client. |
|
19 | + * |
|
20 | + * @param integer $clientId |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function revoke($clientId) |
|
24 | + { |
|
25 | + $client = $this->find($clientId); |
|
26 | + $client->tokens()->update(['revoked' => true]); |
|
27 | + $client->forceFill(['revoked' => true])->save(); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Revoke the given client. |
|
32 | - * |
|
33 | - * @param integer $clientId |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function revoke($clientId) |
|
37 | - { |
|
30 | + /** |
|
31 | + * Revoke the given client. |
|
32 | + * |
|
33 | + * @param integer $clientId |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function revoke($clientId) |
|
37 | + { |
|
38 | 38 | $this->update($clientId, ['secret' => str_random(40)]); |
39 | - } |
|
39 | + } |
|
40 | 40 | } |
@@ -6,23 +6,23 @@ |
||
6 | 6 | |
7 | 7 | class OauthClient extends Client |
8 | 8 | { |
9 | - protected $dates = ['created_at', 'updated_at']; |
|
10 | - protected $fillable = ['name', 'redirect', 'user_id', 'personal_access_client', 'password_client', 'revoked']; |
|
11 | - public $searchable = ['name']; |
|
9 | + protected $dates = ['created_at', 'updated_at']; |
|
10 | + protected $fillable = ['name', 'redirect', 'user_id', 'personal_access_client', 'password_client', 'revoked']; |
|
11 | + public $searchable = ['name']; |
|
12 | 12 | |
13 | - public function getCreatedAtAttribute($value) |
|
14 | - { |
|
15 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
16 | - } |
|
13 | + public function getCreatedAtAttribute($value) |
|
14 | + { |
|
15 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
16 | + } |
|
17 | 17 | |
18 | - public function getUpdatedAtAttribute($value) |
|
19 | - { |
|
20 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | - } |
|
18 | + public function getUpdatedAtAttribute($value) |
|
19 | + { |
|
20 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21 | + } |
|
22 | 22 | |
23 | - public static function boot() |
|
24 | - { |
|
25 | - parent::boot(); |
|
26 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\OauthClientObserver')); |
|
27 | - } |
|
23 | + public static function boot() |
|
24 | + { |
|
25 | + parent::boot(); |
|
26 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\OauthClientObserver')); |
|
27 | + } |
|
28 | 28 | } |