@@ -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', 'two_factor_code']; |
|
| 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', 'two_factor_code']; |
|
| 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 | } |
@@ -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 | - * Regenerate seceret for the given client. |
|
| 32 | - * |
|
| 33 | - * @param integer $clientId |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function regenerateSecret($clientId) |
|
| 37 | - { |
|
| 30 | + /** |
|
| 31 | + * Regenerate seceret for the given client. |
|
| 32 | + * |
|
| 33 | + * @param integer $clientId |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function regenerateSecret($clientId) |
|
| 37 | + { |
|
| 38 | 38 | $this->update($clientId, ['secret' => str_random(40)]); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -5,355 +5,355 @@ |
||
| 5 | 5 | |
| 6 | 6 | class UserRepository extends AbstractRepository |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Return the model full namespace. |
|
| 10 | - * |
|
| 11 | - * @return string |
|
| 12 | - */ |
|
| 13 | - protected function getModel() |
|
| 14 | - { |
|
| 15 | - return 'App\Modules\V1\Acl\AclUser'; |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Return the logged in user account. |
|
| 21 | - * |
|
| 22 | - * @param array $relations |
|
| 23 | - * @return boolean |
|
| 24 | - */ |
|
| 25 | - public function account($relations = []) |
|
| 26 | - { |
|
| 27 | - $permissions = []; |
|
| 28 | - $user = \Core::users()->find(\Auth::id(), $relations); |
|
| 29 | - foreach ($user->groups()->get() as $group) |
|
| 30 | - { |
|
| 31 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 32 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
| 33 | - }); |
|
| 34 | - } |
|
| 35 | - $user->permissions = $permissions; |
|
| 36 | - |
|
| 37 | - return $user; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Check if the logged in user or the given user |
|
| 42 | - * has the given permissions on the given model. |
|
| 43 | - * |
|
| 44 | - * @param string $nameOfPermission |
|
| 45 | - * @param string $model |
|
| 46 | - * @param boolean $user |
|
| 47 | - * @return boolean |
|
| 48 | - */ |
|
| 49 | - public function can($nameOfPermission, $model, $user = false) |
|
| 50 | - { |
|
| 51 | - $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
|
| 52 | - $permissions = []; |
|
| 53 | - |
|
| 54 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 55 | - $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
| 56 | - }); |
|
| 8 | + /** |
|
| 9 | + * Return the model full namespace. |
|
| 10 | + * |
|
| 11 | + * @return string |
|
| 12 | + */ |
|
| 13 | + protected function getModel() |
|
| 14 | + { |
|
| 15 | + return 'App\Modules\V1\Acl\AclUser'; |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Return the logged in user account. |
|
| 21 | + * |
|
| 22 | + * @param array $relations |
|
| 23 | + * @return boolean |
|
| 24 | + */ |
|
| 25 | + public function account($relations = []) |
|
| 26 | + { |
|
| 27 | + $permissions = []; |
|
| 28 | + $user = \Core::users()->find(\Auth::id(), $relations); |
|
| 29 | + foreach ($user->groups()->get() as $group) |
|
| 30 | + { |
|
| 31 | + $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 32 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
| 33 | + }); |
|
| 34 | + } |
|
| 35 | + $user->permissions = $permissions; |
|
| 36 | + |
|
| 37 | + return $user; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Check if the logged in user or the given user |
|
| 42 | + * has the given permissions on the given model. |
|
| 43 | + * |
|
| 44 | + * @param string $nameOfPermission |
|
| 45 | + * @param string $model |
|
| 46 | + * @param boolean $user |
|
| 47 | + * @return boolean |
|
| 48 | + */ |
|
| 49 | + public function can($nameOfPermission, $model, $user = false) |
|
| 50 | + { |
|
| 51 | + $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
|
| 52 | + $permissions = []; |
|
| 53 | + |
|
| 54 | + $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 55 | + $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
| 56 | + }); |
|
| 57 | 57 | |
| 58 | - return in_array($nameOfPermission, $permissions); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Check if the logged in user has the given group. |
|
| 63 | - * |
|
| 64 | - * @param string $groupName |
|
| 65 | - * @param integer $userId |
|
| 66 | - * @return boolean |
|
| 67 | - */ |
|
| 68 | - public function hasGroup($groupName, $userId = false) |
|
| 69 | - { |
|
| 70 | - $userId = $userId ?: \Auth::id(); |
|
| 71 | - $groups = $this->find($userId)->groups; |
|
| 72 | - return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Assign the given group ids to the given user. |
|
| 77 | - * |
|
| 78 | - * @param integer $user_id |
|
| 79 | - * @param array $group_ids |
|
| 80 | - * @return object |
|
| 81 | - */ |
|
| 82 | - public function assignGroups($user_id, $group_ids) |
|
| 83 | - { |
|
| 84 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 85 | - $user = $this->find($user_id); |
|
| 86 | - $user->groups()->detach(); |
|
| 87 | - $user->groups()->attach($group_ids); |
|
| 88 | - }); |
|
| 89 | - |
|
| 90 | - return $this->find($user_id); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Handle a login request to the application. |
|
| 95 | - * |
|
| 96 | - * @param array $credentials |
|
| 97 | - * @param boolean $adminLogin |
|
| 98 | - * @return object |
|
| 99 | - */ |
|
| 100 | - public function login($credentials, $adminLogin = false) |
|
| 101 | - { |
|
| 102 | - if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
| 103 | - { |
|
| 104 | - \ErrorHandler::loginFailed(); |
|
| 105 | - } |
|
| 106 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
| 107 | - { |
|
| 108 | - \ErrorHandler::loginFailed(); |
|
| 109 | - } |
|
| 110 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 111 | - { |
|
| 112 | - \ErrorHandler::loginFailed(); |
|
| 113 | - } |
|
| 114 | - else if ($user->blocked) |
|
| 115 | - { |
|
| 116 | - \ErrorHandler::userIsBlocked(); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $user; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Handle a social login request of the none admin to the application. |
|
| 124 | - * |
|
| 125 | - * @param array $credentials |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function loginSocial($credentials) |
|
| 129 | - { |
|
| 130 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
| 131 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
| 132 | - |
|
| 133 | - if ( ! $user->email) |
|
| 134 | - { |
|
| 135 | - \ErrorHandler::noSocialEmail(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
| 139 | - { |
|
| 140 | - $data = ['email' => $user->email, 'password' => '']; |
|
| 141 | - return $this->register($data); |
|
| 142 | - } |
|
| 143 | - else |
|
| 144 | - { |
|
| 145 | - if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
| 146 | - { |
|
| 147 | - \ErrorHandler::userAlreadyRegistered(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
| 151 | - return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
| 152 | - } |
|
| 153 | - } |
|
| 58 | + return in_array($nameOfPermission, $permissions); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Check if the logged in user has the given group. |
|
| 63 | + * |
|
| 64 | + * @param string $groupName |
|
| 65 | + * @param integer $userId |
|
| 66 | + * @return boolean |
|
| 67 | + */ |
|
| 68 | + public function hasGroup($groupName, $userId = false) |
|
| 69 | + { |
|
| 70 | + $userId = $userId ?: \Auth::id(); |
|
| 71 | + $groups = $this->find($userId)->groups; |
|
| 72 | + return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Assign the given group ids to the given user. |
|
| 77 | + * |
|
| 78 | + * @param integer $user_id |
|
| 79 | + * @param array $group_ids |
|
| 80 | + * @return object |
|
| 81 | + */ |
|
| 82 | + public function assignGroups($user_id, $group_ids) |
|
| 83 | + { |
|
| 84 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 85 | + $user = $this->find($user_id); |
|
| 86 | + $user->groups()->detach(); |
|
| 87 | + $user->groups()->attach($group_ids); |
|
| 88 | + }); |
|
| 89 | + |
|
| 90 | + return $this->find($user_id); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Handle a login request to the application. |
|
| 95 | + * |
|
| 96 | + * @param array $credentials |
|
| 97 | + * @param boolean $adminLogin |
|
| 98 | + * @return object |
|
| 99 | + */ |
|
| 100 | + public function login($credentials, $adminLogin = false) |
|
| 101 | + { |
|
| 102 | + if ( ! $user = $this->first(['email' => $credentials['email']])) |
|
| 103 | + { |
|
| 104 | + \ErrorHandler::loginFailed(); |
|
| 105 | + } |
|
| 106 | + else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
| 107 | + { |
|
| 108 | + \ErrorHandler::loginFailed(); |
|
| 109 | + } |
|
| 110 | + else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 111 | + { |
|
| 112 | + \ErrorHandler::loginFailed(); |
|
| 113 | + } |
|
| 114 | + else if ($user->blocked) |
|
| 115 | + { |
|
| 116 | + \ErrorHandler::userIsBlocked(); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $user; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Handle a social login request of the none admin to the application. |
|
| 124 | + * |
|
| 125 | + * @param array $credentials |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function loginSocial($credentials) |
|
| 129 | + { |
|
| 130 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
| 131 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
| 132 | + |
|
| 133 | + if ( ! $user->email) |
|
| 134 | + { |
|
| 135 | + \ErrorHandler::noSocialEmail(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
| 139 | + { |
|
| 140 | + $data = ['email' => $user->email, 'password' => '']; |
|
| 141 | + return $this->register($data); |
|
| 142 | + } |
|
| 143 | + else |
|
| 144 | + { |
|
| 145 | + if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
| 146 | + { |
|
| 147 | + \ErrorHandler::userAlreadyRegistered(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
| 151 | + return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Handle a registration request. |
|
| 157 | - * |
|
| 158 | - * @param array $credentials |
|
| 159 | - * @return array |
|
| 160 | - */ |
|
| 161 | - public function register($credentials) |
|
| 162 | - { |
|
| 163 | - $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
| 164 | - $this->model->create($credentials); |
|
| 165 | - |
|
| 166 | - return $loginProxy->login($credentials, 0); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Block the user. |
|
| 171 | - * |
|
| 172 | - * @param integer $user_id |
|
| 173 | - * @return object |
|
| 174 | - */ |
|
| 175 | - public function block($user_id) |
|
| 176 | - { |
|
| 177 | - if ( ! $user = $this->find($user_id)) |
|
| 178 | - { |
|
| 179 | - \ErrorHandler::notFound('user'); |
|
| 180 | - } |
|
| 181 | - if ( ! $this->hasGroup('Admin')) |
|
| 182 | - { |
|
| 183 | - \ErrorHandler::noPermissions(); |
|
| 184 | - } |
|
| 185 | - else if (\Auth::id() == $user_id) |
|
| 186 | - { |
|
| 187 | - \ErrorHandler::noPermissions(); |
|
| 188 | - } |
|
| 189 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 190 | - { |
|
| 191 | - \ErrorHandler::noPermissions(); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $user->blocked = 1; |
|
| 195 | - $user->save(); |
|
| 155 | + /** |
|
| 156 | + * Handle a registration request. |
|
| 157 | + * |
|
| 158 | + * @param array $credentials |
|
| 159 | + * @return array |
|
| 160 | + */ |
|
| 161 | + public function register($credentials) |
|
| 162 | + { |
|
| 163 | + $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
| 164 | + $this->model->create($credentials); |
|
| 165 | + |
|
| 166 | + return $loginProxy->login($credentials, 0); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Block the user. |
|
| 171 | + * |
|
| 172 | + * @param integer $user_id |
|
| 173 | + * @return object |
|
| 174 | + */ |
|
| 175 | + public function block($user_id) |
|
| 176 | + { |
|
| 177 | + if ( ! $user = $this->find($user_id)) |
|
| 178 | + { |
|
| 179 | + \ErrorHandler::notFound('user'); |
|
| 180 | + } |
|
| 181 | + if ( ! $this->hasGroup('Admin')) |
|
| 182 | + { |
|
| 183 | + \ErrorHandler::noPermissions(); |
|
| 184 | + } |
|
| 185 | + else if (\Auth::id() == $user_id) |
|
| 186 | + { |
|
| 187 | + \ErrorHandler::noPermissions(); |
|
| 188 | + } |
|
| 189 | + else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 190 | + { |
|
| 191 | + \ErrorHandler::noPermissions(); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $user->blocked = 1; |
|
| 195 | + $user->save(); |
|
| 196 | 196 | |
| 197 | - return $user; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Unblock the user. |
|
| 202 | - * |
|
| 203 | - * @param integer $user_id |
|
| 204 | - * @return object |
|
| 205 | - */ |
|
| 206 | - public function unblock($user_id) |
|
| 207 | - { |
|
| 208 | - if ( ! $this->hasGroup('Admin')) |
|
| 209 | - { |
|
| 210 | - \ErrorHandler::noPermissions(); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $user = $this->find($user_id); |
|
| 214 | - $user->blocked = 0; |
|
| 215 | - $user->save(); |
|
| 216 | - |
|
| 217 | - return $user; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Send a reset link to the given user. |
|
| 222 | - * |
|
| 223 | - * @param string $email |
|
| 224 | - * @return void |
|
| 225 | - */ |
|
| 226 | - public function sendReset($email) |
|
| 227 | - { |
|
| 228 | - if ( ! $user = $this->model->where('email', $email)->first()) |
|
| 229 | - { |
|
| 230 | - \ErrorHandler::notFound('email'); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - $url = $this->config['resetLink']; |
|
| 234 | - $token = \Password::getRepository()->create($user); |
|
| 197 | + return $user; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Unblock the user. |
|
| 202 | + * |
|
| 203 | + * @param integer $user_id |
|
| 204 | + * @return object |
|
| 205 | + */ |
|
| 206 | + public function unblock($user_id) |
|
| 207 | + { |
|
| 208 | + if ( ! $this->hasGroup('Admin')) |
|
| 209 | + { |
|
| 210 | + \ErrorHandler::noPermissions(); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $user = $this->find($user_id); |
|
| 214 | + $user->blocked = 0; |
|
| 215 | + $user->save(); |
|
| 216 | + |
|
| 217 | + return $user; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Send a reset link to the given user. |
|
| 222 | + * |
|
| 223 | + * @param string $email |
|
| 224 | + * @return void |
|
| 225 | + */ |
|
| 226 | + public function sendReset($email) |
|
| 227 | + { |
|
| 228 | + if ( ! $user = $this->model->where('email', $email)->first()) |
|
| 229 | + { |
|
| 230 | + \ErrorHandler::notFound('email'); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + $url = $this->config['resetLink']; |
|
| 234 | + $token = \Password::getRepository()->create($user); |
|
| 235 | 235 | |
| 236 | - \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
| 237 | - $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
| 238 | - }); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Reset the given user's password. |
|
| 243 | - * |
|
| 244 | - * @param array $credentials |
|
| 245 | - * @return array |
|
| 246 | - */ |
|
| 247 | - public function resetPassword($credentials) |
|
| 248 | - { |
|
| 249 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
| 250 | - $user->password = $password; |
|
| 251 | - $user->save(); |
|
| 252 | - }); |
|
| 253 | - |
|
| 254 | - switch ($response) { |
|
| 255 | - case \Password::PASSWORD_RESET: |
|
| 256 | - return 'success'; |
|
| 236 | + \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
| 237 | + $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
|
| 238 | + }); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Reset the given user's password. |
|
| 243 | + * |
|
| 244 | + * @param array $credentials |
|
| 245 | + * @return array |
|
| 246 | + */ |
|
| 247 | + public function resetPassword($credentials) |
|
| 248 | + { |
|
| 249 | + $response = \Password::reset($credentials, function ($user, $password) { |
|
| 250 | + $user->password = $password; |
|
| 251 | + $user->save(); |
|
| 252 | + }); |
|
| 253 | + |
|
| 254 | + switch ($response) { |
|
| 255 | + case \Password::PASSWORD_RESET: |
|
| 256 | + return 'success'; |
|
| 257 | 257 | |
| 258 | - case \Password::INVALID_TOKEN: |
|
| 259 | - \ErrorHandler::invalidResetToken('token'); |
|
| 260 | - |
|
| 261 | - case \Password::INVALID_PASSWORD: |
|
| 262 | - \ErrorHandler::invalidResetPassword('email'); |
|
| 263 | - |
|
| 264 | - case \Password::INVALID_USER: |
|
| 265 | - \ErrorHandler::notFound('user'); |
|
| 266 | - |
|
| 267 | - default: |
|
| 268 | - \ErrorHandler::generalError(); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Change the logged in user password. |
|
| 274 | - * |
|
| 275 | - * @param array $credentials |
|
| 276 | - * @return void |
|
| 277 | - */ |
|
| 278 | - public function changePassword($credentials) |
|
| 279 | - { |
|
| 280 | - $user = \Auth::user(); |
|
| 281 | - if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
| 282 | - { |
|
| 283 | - \ErrorHandler::invalidOldPassword(); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $user->password = $credentials['password']; |
|
| 287 | - $user->save(); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Paginate all users in the given group based on the given conditions. |
|
| 292 | - * |
|
| 293 | - * @param string $groupName |
|
| 294 | - * @param array $relations |
|
| 295 | - * @param integer $perPage |
|
| 296 | - * @param string $sortBy |
|
| 297 | - * @param boolean $desc |
|
| 298 | - * @return \Illuminate\Http\Response |
|
| 299 | - */ |
|
| 300 | - public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
| 301 | - { |
|
| 302 | - unset($conditions['page']); |
|
| 303 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
| 304 | - $sort = $desc ? 'desc' : 'asc'; |
|
| 305 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
| 306 | - |
|
| 307 | - $model->whereHas('groups', function($q) use ($groupName){ |
|
| 308 | - $q->where('name', $groupName); |
|
| 309 | - }); |
|
| 258 | + case \Password::INVALID_TOKEN: |
|
| 259 | + \ErrorHandler::invalidResetToken('token'); |
|
| 260 | + |
|
| 261 | + case \Password::INVALID_PASSWORD: |
|
| 262 | + \ErrorHandler::invalidResetPassword('email'); |
|
| 263 | + |
|
| 264 | + case \Password::INVALID_USER: |
|
| 265 | + \ErrorHandler::notFound('user'); |
|
| 266 | + |
|
| 267 | + default: |
|
| 268 | + \ErrorHandler::generalError(); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Change the logged in user password. |
|
| 274 | + * |
|
| 275 | + * @param array $credentials |
|
| 276 | + * @return void |
|
| 277 | + */ |
|
| 278 | + public function changePassword($credentials) |
|
| 279 | + { |
|
| 280 | + $user = \Auth::user(); |
|
| 281 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
| 282 | + { |
|
| 283 | + \ErrorHandler::invalidOldPassword(); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $user->password = $credentials['password']; |
|
| 287 | + $user->save(); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Paginate all users in the given group based on the given conditions. |
|
| 292 | + * |
|
| 293 | + * @param string $groupName |
|
| 294 | + * @param array $relations |
|
| 295 | + * @param integer $perPage |
|
| 296 | + * @param string $sortBy |
|
| 297 | + * @param boolean $desc |
|
| 298 | + * @return \Illuminate\Http\Response |
|
| 299 | + */ |
|
| 300 | + public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
| 301 | + { |
|
| 302 | + unset($conditions['page']); |
|
| 303 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
| 304 | + $sort = $desc ? 'desc' : 'asc'; |
|
| 305 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
| 306 | + |
|
| 307 | + $model->whereHas('groups', function($q) use ($groupName){ |
|
| 308 | + $q->where('name', $groupName); |
|
| 309 | + }); |
|
| 310 | 310 | |
| 311 | 311 | |
| 312 | - if (count($conditions['conditionValues'])) |
|
| 313 | - { |
|
| 314 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - if ($perPage) |
|
| 318 | - { |
|
| 319 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return $model->orderBy($sortBy, $sort)->get(); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Save the given data to the logged in user. |
|
| 327 | - * |
|
| 328 | - * @param array $credentials |
|
| 329 | - * @return object |
|
| 330 | - */ |
|
| 331 | - public function saveProfile($credentials) |
|
| 332 | - { |
|
| 333 | - $user = \Auth::user(); |
|
| 334 | - $user->save($credentials); |
|
| 335 | - |
|
| 336 | - return $user; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Ensure access token hasn't expired or revoked. |
|
| 341 | - * |
|
| 342 | - * @param string $accessToken |
|
| 343 | - * @return boolean |
|
| 344 | - */ |
|
| 345 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
| 346 | - { |
|
| 347 | - |
|
| 348 | - $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface'); |
|
| 349 | - $data = new ValidationData(); |
|
| 350 | - $data->setCurrentTime(time()); |
|
| 351 | - |
|
| 352 | - if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
| 353 | - { |
|
| 354 | - return true; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - return false; |
|
| 358 | - } |
|
| 312 | + if (count($conditions['conditionValues'])) |
|
| 313 | + { |
|
| 314 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + if ($perPage) |
|
| 318 | + { |
|
| 319 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return $model->orderBy($sortBy, $sort)->get(); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Save the given data to the logged in user. |
|
| 327 | + * |
|
| 328 | + * @param array $credentials |
|
| 329 | + * @return object |
|
| 330 | + */ |
|
| 331 | + public function saveProfile($credentials) |
|
| 332 | + { |
|
| 333 | + $user = \Auth::user(); |
|
| 334 | + $user->save($credentials); |
|
| 335 | + |
|
| 336 | + return $user; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Ensure access token hasn't expired or revoked. |
|
| 341 | + * |
|
| 342 | + * @param string $accessToken |
|
| 343 | + * @return boolean |
|
| 344 | + */ |
|
| 345 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
| 346 | + { |
|
| 347 | + |
|
| 348 | + $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface'); |
|
| 349 | + $data = new ValidationData(); |
|
| 350 | + $data->setCurrentTime(time()); |
|
| 351 | + |
|
| 352 | + if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
| 353 | + { |
|
| 354 | + return true; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + return false; |
|
| 358 | + } |
|
| 359 | 359 | } |
@@ -13,30 +13,30 @@ |
||
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | 15 | Schema::create('users', function (Blueprint $table) { |
| 16 | - $table->increments('id'); |
|
| 17 | - $table->string('name', 100)->nullable(); |
|
| 18 | - $table->string('email')->unique(); |
|
| 19 | - $table->string('password', 60)->nullable(); |
|
| 20 | - $table->boolean('blocked')->default(0); |
|
| 16 | + $table->increments('id'); |
|
| 17 | + $table->string('name', 100)->nullable(); |
|
| 18 | + $table->string('email')->unique(); |
|
| 19 | + $table->string('password', 60)->nullable(); |
|
| 20 | + $table->boolean('blocked')->default(0); |
|
| 21 | 21 | $table->date('last_change_password')->nullable(); |
| 22 | - $table->string('two_factor_code', 4)->nullable(); |
|
| 23 | - $table->softDeletes(); |
|
| 24 | - $table->rememberToken(); |
|
| 25 | - $table->timestamps(); |
|
| 26 | - }); |
|
| 22 | + $table->string('two_factor_code', 4)->nullable(); |
|
| 23 | + $table->softDeletes(); |
|
| 24 | + $table->rememberToken(); |
|
| 25 | + $table->timestamps(); |
|
| 26 | + }); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Create Default users. |
| 30 | 30 | */ |
| 31 | 31 | \DB::table('users')->insertGetId( |
| 32 | - [ |
|
| 32 | + [ |
|
| 33 | 33 | 'name' => 'Admin', |
| 34 | 34 | 'email' => '[email protected]', |
| 35 | 35 | 'password' => bcrypt('123456'), |
| 36 | 36 | 'created_at' => \DB::raw('NOW()'), |
| 37 | 37 | 'updated_at' => \DB::raw('NOW()') |
| 38 | 38 | ] |
| 39 | - ); |
|
| 39 | + ); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -13,21 +13,21 @@ discard block |
||
| 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(); |
|
| 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 | 28 | |
| 29 | - $table->index(['user_id']); |
|
| 30 | - }); |
|
| 29 | + $table->index(['user_id']); |
|
| 30 | + }); |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Create Default groups. |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | 'created_at' => \DB::raw('NOW()'), |
| 55 | 55 | 'updated_at' => \DB::raw('NOW()') |
| 56 | 56 | ] |
| 57 | - ); |
|
| 57 | + ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -6,94 +6,94 @@ |
||
| 6 | 6 | |
| 7 | 7 | class GroupsTableSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - /** |
|
| 17 | - * Insert the permissions related to groups table. |
|
| 18 | - */ |
|
| 19 | - \DB::table('permissions')->insert( |
|
| 20 | - [ |
|
| 21 | - /** |
|
| 22 | - * Groups model permissions. |
|
| 23 | - */ |
|
| 24 | - [ |
|
| 25 | - 'name' => 'save', |
|
| 26 | - 'model' => 'groups', |
|
| 27 | - 'created_at' => \DB::raw('NOW()'), |
|
| 28 | - 'updated_at' => \DB::raw('NOW()') |
|
| 29 | - ], |
|
| 30 | - [ |
|
| 31 | - 'name' => 'delete', |
|
| 32 | - 'model' => 'groups', |
|
| 33 | - 'created_at' => \DB::raw('NOW()'), |
|
| 34 | - 'updated_at' => \DB::raw('NOW()') |
|
| 35 | - ], |
|
| 36 | - [ |
|
| 37 | - 'name' => 'find', |
|
| 38 | - 'model' => 'groups', |
|
| 39 | - 'created_at' => \DB::raw('NOW()'), |
|
| 40 | - 'updated_at' => \DB::raw('NOW()') |
|
| 41 | - ], |
|
| 42 | - [ |
|
| 43 | - 'name' => 'search', |
|
| 44 | - 'model' => 'groups', |
|
| 45 | - 'created_at' => \DB::raw('NOW()'), |
|
| 46 | - 'updated_at' => \DB::raw('NOW()') |
|
| 47 | - ], |
|
| 48 | - [ |
|
| 49 | - 'name' => 'list', |
|
| 50 | - 'model' => 'groups', |
|
| 51 | - 'created_at' => \DB::raw('NOW()'), |
|
| 52 | - 'updated_at' => \DB::raw('NOW()') |
|
| 53 | - ], |
|
| 54 | - [ |
|
| 55 | - 'name' => 'findby', |
|
| 56 | - 'model' => 'groups', |
|
| 57 | - 'created_at' => \DB::raw('NOW()'), |
|
| 58 | - 'updated_at' => \DB::raw('NOW()') |
|
| 59 | - ], |
|
| 60 | - [ |
|
| 61 | - 'name' => 'first', |
|
| 62 | - 'model' => 'groups', |
|
| 63 | - 'created_at' => \DB::raw('NOW()'), |
|
| 64 | - 'updated_at' => \DB::raw('NOW()') |
|
| 65 | - ], |
|
| 66 | - [ |
|
| 67 | - 'name' => 'paginate', |
|
| 68 | - 'model' => 'groups', |
|
| 69 | - 'created_at' => \DB::raw('NOW()'), |
|
| 70 | - 'updated_at' => \DB::raw('NOW()') |
|
| 71 | - ], |
|
| 72 | - [ |
|
| 73 | - 'name' => 'paginateby', |
|
| 74 | - 'model' => 'groups', |
|
| 75 | - 'created_at' => \DB::raw('NOW()'), |
|
| 76 | - 'updated_at' => \DB::raw('NOW()') |
|
| 77 | - ], |
|
| 78 | - [ |
|
| 79 | - 'name' => 'assignpermissions', |
|
| 80 | - 'model' => 'groups', |
|
| 81 | - 'created_at' => \DB::raw('NOW()'), |
|
| 82 | - 'updated_at' => \DB::raw('NOW()') |
|
| 83 | - ], |
|
| 84 | - [ |
|
| 85 | - 'name' => 'deleted', |
|
| 86 | - 'model' => 'groups', |
|
| 87 | - 'created_at' => \DB::raw('NOW()'), |
|
| 88 | - 'updated_at' => \DB::raw('NOW()') |
|
| 89 | - ], |
|
| 90 | - [ |
|
| 91 | - 'name' => 'restore', |
|
| 92 | - 'model' => 'groups', |
|
| 93 | - 'created_at' => \DB::raw('NOW()'), |
|
| 94 | - 'updated_at' => \DB::raw('NOW()') |
|
| 95 | - ] |
|
| 96 | - ] |
|
| 97 | - ); |
|
| 98 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + /** |
|
| 17 | + * Insert the permissions related to groups table. |
|
| 18 | + */ |
|
| 19 | + \DB::table('permissions')->insert( |
|
| 20 | + [ |
|
| 21 | + /** |
|
| 22 | + * Groups model permissions. |
|
| 23 | + */ |
|
| 24 | + [ |
|
| 25 | + 'name' => 'save', |
|
| 26 | + 'model' => 'groups', |
|
| 27 | + 'created_at' => \DB::raw('NOW()'), |
|
| 28 | + 'updated_at' => \DB::raw('NOW()') |
|
| 29 | + ], |
|
| 30 | + [ |
|
| 31 | + 'name' => 'delete', |
|
| 32 | + 'model' => 'groups', |
|
| 33 | + 'created_at' => \DB::raw('NOW()'), |
|
| 34 | + 'updated_at' => \DB::raw('NOW()') |
|
| 35 | + ], |
|
| 36 | + [ |
|
| 37 | + 'name' => 'find', |
|
| 38 | + 'model' => 'groups', |
|
| 39 | + 'created_at' => \DB::raw('NOW()'), |
|
| 40 | + 'updated_at' => \DB::raw('NOW()') |
|
| 41 | + ], |
|
| 42 | + [ |
|
| 43 | + 'name' => 'search', |
|
| 44 | + 'model' => 'groups', |
|
| 45 | + 'created_at' => \DB::raw('NOW()'), |
|
| 46 | + 'updated_at' => \DB::raw('NOW()') |
|
| 47 | + ], |
|
| 48 | + [ |
|
| 49 | + 'name' => 'list', |
|
| 50 | + 'model' => 'groups', |
|
| 51 | + 'created_at' => \DB::raw('NOW()'), |
|
| 52 | + 'updated_at' => \DB::raw('NOW()') |
|
| 53 | + ], |
|
| 54 | + [ |
|
| 55 | + 'name' => 'findby', |
|
| 56 | + 'model' => 'groups', |
|
| 57 | + 'created_at' => \DB::raw('NOW()'), |
|
| 58 | + 'updated_at' => \DB::raw('NOW()') |
|
| 59 | + ], |
|
| 60 | + [ |
|
| 61 | + 'name' => 'first', |
|
| 62 | + 'model' => 'groups', |
|
| 63 | + 'created_at' => \DB::raw('NOW()'), |
|
| 64 | + 'updated_at' => \DB::raw('NOW()') |
|
| 65 | + ], |
|
| 66 | + [ |
|
| 67 | + 'name' => 'paginate', |
|
| 68 | + 'model' => 'groups', |
|
| 69 | + 'created_at' => \DB::raw('NOW()'), |
|
| 70 | + 'updated_at' => \DB::raw('NOW()') |
|
| 71 | + ], |
|
| 72 | + [ |
|
| 73 | + 'name' => 'paginateby', |
|
| 74 | + 'model' => 'groups', |
|
| 75 | + 'created_at' => \DB::raw('NOW()'), |
|
| 76 | + 'updated_at' => \DB::raw('NOW()') |
|
| 77 | + ], |
|
| 78 | + [ |
|
| 79 | + 'name' => 'assignpermissions', |
|
| 80 | + 'model' => 'groups', |
|
| 81 | + 'created_at' => \DB::raw('NOW()'), |
|
| 82 | + 'updated_at' => \DB::raw('NOW()') |
|
| 83 | + ], |
|
| 84 | + [ |
|
| 85 | + 'name' => 'deleted', |
|
| 86 | + 'model' => 'groups', |
|
| 87 | + 'created_at' => \DB::raw('NOW()'), |
|
| 88 | + 'updated_at' => \DB::raw('NOW()') |
|
| 89 | + ], |
|
| 90 | + [ |
|
| 91 | + 'name' => 'restore', |
|
| 92 | + 'model' => 'groups', |
|
| 93 | + 'created_at' => \DB::raw('NOW()'), |
|
| 94 | + 'updated_at' => \DB::raw('NOW()') |
|
| 95 | + ] |
|
| 96 | + ] |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -6,112 +6,112 @@ |
||
| 6 | 6 | |
| 7 | 7 | class UsersTableSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - /** |
|
| 17 | - * Insert the permissions related to users table. |
|
| 18 | - */ |
|
| 19 | - \DB::table('permissions')->insert( |
|
| 20 | - [ |
|
| 21 | - /** |
|
| 22 | - * Users model permissions. |
|
| 23 | - */ |
|
| 24 | - [ |
|
| 25 | - 'name' => 'save', |
|
| 26 | - 'model' => 'users', |
|
| 27 | - 'created_at' => \DB::raw('NOW()'), |
|
| 28 | - 'updated_at' => \DB::raw('NOW()') |
|
| 29 | - ], |
|
| 30 | - [ |
|
| 31 | - 'name' => 'delete', |
|
| 32 | - 'model' => 'users', |
|
| 33 | - 'created_at' => \DB::raw('NOW()'), |
|
| 34 | - 'updated_at' => \DB::raw('NOW()') |
|
| 35 | - ], |
|
| 36 | - [ |
|
| 37 | - 'name' => 'find', |
|
| 38 | - 'model' => 'users', |
|
| 39 | - 'created_at' => \DB::raw('NOW()'), |
|
| 40 | - 'updated_at' => \DB::raw('NOW()') |
|
| 41 | - ], |
|
| 42 | - [ |
|
| 43 | - 'name' => 'list', |
|
| 44 | - 'model' => 'users', |
|
| 45 | - 'created_at' => \DB::raw('NOW()'), |
|
| 46 | - 'updated_at' => \DB::raw('NOW()') |
|
| 47 | - ], |
|
| 48 | - [ |
|
| 49 | - 'name' => 'search', |
|
| 50 | - 'model' => 'users', |
|
| 51 | - 'created_at' => \DB::raw('NOW()'), |
|
| 52 | - 'updated_at' => \DB::raw('NOW()') |
|
| 53 | - ], |
|
| 54 | - [ |
|
| 55 | - 'name' => 'findby', |
|
| 56 | - 'model' => 'users', |
|
| 57 | - 'created_at' => \DB::raw('NOW()'), |
|
| 58 | - 'updated_at' => \DB::raw('NOW()') |
|
| 59 | - ], |
|
| 60 | - [ |
|
| 61 | - 'name' => 'first', |
|
| 62 | - 'model' => 'users', |
|
| 63 | - 'created_at' => \DB::raw('NOW()'), |
|
| 64 | - 'updated_at' => \DB::raw('NOW()') |
|
| 65 | - ], |
|
| 66 | - [ |
|
| 67 | - 'name' => 'paginate', |
|
| 68 | - 'model' => 'users', |
|
| 69 | - 'created_at' => \DB::raw('NOW()'), |
|
| 70 | - 'updated_at' => \DB::raw('NOW()') |
|
| 71 | - ], |
|
| 72 | - [ |
|
| 73 | - 'name' => 'paginateby', |
|
| 74 | - 'model' => 'users', |
|
| 75 | - 'created_at' => \DB::raw('NOW()'), |
|
| 76 | - 'updated_at' => \DB::raw('NOW()') |
|
| 77 | - ], |
|
| 78 | - [ |
|
| 79 | - 'name' => 'assigngroups', |
|
| 80 | - 'model' => 'users', |
|
| 81 | - 'created_at' => \DB::raw('NOW()'), |
|
| 82 | - 'updated_at' => \DB::raw('NOW()') |
|
| 83 | - ], |
|
| 84 | - [ |
|
| 85 | - 'name' => 'block', |
|
| 86 | - 'model' => 'users', |
|
| 87 | - 'created_at' => \DB::raw('NOW()'), |
|
| 88 | - 'updated_at' => \DB::raw('NOW()') |
|
| 89 | - ], |
|
| 90 | - [ |
|
| 91 | - 'name' => 'unblock', |
|
| 92 | - 'model' => 'users', |
|
| 93 | - 'created_at' => \DB::raw('NOW()'), |
|
| 94 | - 'updated_at' => \DB::raw('NOW()') |
|
| 95 | - ], |
|
| 96 | - [ |
|
| 97 | - 'name' => 'group', |
|
| 98 | - 'model' => 'users', |
|
| 99 | - 'created_at' => \DB::raw('NOW()'), |
|
| 100 | - 'updated_at' => \DB::raw('NOW()') |
|
| 101 | - ], |
|
| 102 | - [ |
|
| 103 | - 'name' => 'deleted', |
|
| 104 | - 'model' => 'users', |
|
| 105 | - 'created_at' => \DB::raw('NOW()'), |
|
| 106 | - 'updated_at' => \DB::raw('NOW()') |
|
| 107 | - ], |
|
| 108 | - [ |
|
| 109 | - 'name' => 'restore', |
|
| 110 | - 'model' => 'users', |
|
| 111 | - 'created_at' => \DB::raw('NOW()'), |
|
| 112 | - 'updated_at' => \DB::raw('NOW()') |
|
| 113 | - ] |
|
| 114 | - ] |
|
| 115 | - ); |
|
| 116 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + /** |
|
| 17 | + * Insert the permissions related to users table. |
|
| 18 | + */ |
|
| 19 | + \DB::table('permissions')->insert( |
|
| 20 | + [ |
|
| 21 | + /** |
|
| 22 | + * Users model permissions. |
|
| 23 | + */ |
|
| 24 | + [ |
|
| 25 | + 'name' => 'save', |
|
| 26 | + 'model' => 'users', |
|
| 27 | + 'created_at' => \DB::raw('NOW()'), |
|
| 28 | + 'updated_at' => \DB::raw('NOW()') |
|
| 29 | + ], |
|
| 30 | + [ |
|
| 31 | + 'name' => 'delete', |
|
| 32 | + 'model' => 'users', |
|
| 33 | + 'created_at' => \DB::raw('NOW()'), |
|
| 34 | + 'updated_at' => \DB::raw('NOW()') |
|
| 35 | + ], |
|
| 36 | + [ |
|
| 37 | + 'name' => 'find', |
|
| 38 | + 'model' => 'users', |
|
| 39 | + 'created_at' => \DB::raw('NOW()'), |
|
| 40 | + 'updated_at' => \DB::raw('NOW()') |
|
| 41 | + ], |
|
| 42 | + [ |
|
| 43 | + 'name' => 'list', |
|
| 44 | + 'model' => 'users', |
|
| 45 | + 'created_at' => \DB::raw('NOW()'), |
|
| 46 | + 'updated_at' => \DB::raw('NOW()') |
|
| 47 | + ], |
|
| 48 | + [ |
|
| 49 | + 'name' => 'search', |
|
| 50 | + 'model' => 'users', |
|
| 51 | + 'created_at' => \DB::raw('NOW()'), |
|
| 52 | + 'updated_at' => \DB::raw('NOW()') |
|
| 53 | + ], |
|
| 54 | + [ |
|
| 55 | + 'name' => 'findby', |
|
| 56 | + 'model' => 'users', |
|
| 57 | + 'created_at' => \DB::raw('NOW()'), |
|
| 58 | + 'updated_at' => \DB::raw('NOW()') |
|
| 59 | + ], |
|
| 60 | + [ |
|
| 61 | + 'name' => 'first', |
|
| 62 | + 'model' => 'users', |
|
| 63 | + 'created_at' => \DB::raw('NOW()'), |
|
| 64 | + 'updated_at' => \DB::raw('NOW()') |
|
| 65 | + ], |
|
| 66 | + [ |
|
| 67 | + 'name' => 'paginate', |
|
| 68 | + 'model' => 'users', |
|
| 69 | + 'created_at' => \DB::raw('NOW()'), |
|
| 70 | + 'updated_at' => \DB::raw('NOW()') |
|
| 71 | + ], |
|
| 72 | + [ |
|
| 73 | + 'name' => 'paginateby', |
|
| 74 | + 'model' => 'users', |
|
| 75 | + 'created_at' => \DB::raw('NOW()'), |
|
| 76 | + 'updated_at' => \DB::raw('NOW()') |
|
| 77 | + ], |
|
| 78 | + [ |
|
| 79 | + 'name' => 'assigngroups', |
|
| 80 | + 'model' => 'users', |
|
| 81 | + 'created_at' => \DB::raw('NOW()'), |
|
| 82 | + 'updated_at' => \DB::raw('NOW()') |
|
| 83 | + ], |
|
| 84 | + [ |
|
| 85 | + 'name' => 'block', |
|
| 86 | + 'model' => 'users', |
|
| 87 | + 'created_at' => \DB::raw('NOW()'), |
|
| 88 | + 'updated_at' => \DB::raw('NOW()') |
|
| 89 | + ], |
|
| 90 | + [ |
|
| 91 | + 'name' => 'unblock', |
|
| 92 | + 'model' => 'users', |
|
| 93 | + 'created_at' => \DB::raw('NOW()'), |
|
| 94 | + 'updated_at' => \DB::raw('NOW()') |
|
| 95 | + ], |
|
| 96 | + [ |
|
| 97 | + 'name' => 'group', |
|
| 98 | + 'model' => 'users', |
|
| 99 | + 'created_at' => \DB::raw('NOW()'), |
|
| 100 | + 'updated_at' => \DB::raw('NOW()') |
|
| 101 | + ], |
|
| 102 | + [ |
|
| 103 | + 'name' => 'deleted', |
|
| 104 | + 'model' => 'users', |
|
| 105 | + 'created_at' => \DB::raw('NOW()'), |
|
| 106 | + 'updated_at' => \DB::raw('NOW()') |
|
| 107 | + ], |
|
| 108 | + [ |
|
| 109 | + 'name' => 'restore', |
|
| 110 | + 'model' => 'users', |
|
| 111 | + 'created_at' => \DB::raw('NOW()'), |
|
| 112 | + 'updated_at' => \DB::raw('NOW()') |
|
| 113 | + ] |
|
| 114 | + ] |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -6,20 +6,20 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | class AssignRelationsSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 18 | + /** |
|
| 19 | 19 | * Assign the permissions to the admin group. |
| 20 | 20 | */ |
| 21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients'])->each(function ($permission) use ($adminGroupId) { |
|
| 22 | - \DB::table('groups_permissions')->insert( |
|
| 21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients'])->each(function ($permission) use ($adminGroupId) { |
|
| 22 | + \DB::table('groups_permissions')->insert( |
|
| 23 | 23 | [ |
| 24 | 24 | 'permission_id' => $permission->id, |
| 25 | 25 | 'group_id' => $adminGroupId, |
@@ -27,6 +27,6 @@ discard block |
||
| 27 | 27 | 'updated_at' => \DB::raw('NOW()') |
| 28 | 28 | ] |
| 29 | 29 | ); |
| 30 | - }); |
|
| 31 | - } |
|
| 30 | + }); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ClearDataSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $permissions = \DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients']); |
|
| 17 | - \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | - $permissions->delete(); |
|
| 19 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $permissions = \DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups', 'oauthClients']); |
|
| 17 | + \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | + $permissions->delete(); |
|
| 19 | + } |
|
| 20 | 20 | } |