diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index b251b65bd..295a70190 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -12,7 +12,7 @@ use DB; use App\User; use App\Models\Esi\EsiScope; use App\Models\Esi\EsiToken; -use App\Models\User\UserRole; +use App\Models\user\Permission; use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Configuration; @@ -111,6 +111,12 @@ class LoginController extends Controller 'owner_hash' => $eve_user->owner_hash, 'role' => $role, ]); + //Update the user's roles and permission + UserPermission::where(['character_id' => $eve_user->id])->delete(); + $perm = new UserPermission(); + $perm->character_id = $eve_user->id; + $perm->permission = $role; + $perm->save(); } else { //Update the user information never the less. DB::table('users')->where('character_id', $eve_user->id)->update([ @@ -178,11 +184,10 @@ class LoginController extends Controller * @param charId */ private function SetRole($role, $charId) { - //Insert the role into the database - $roles = new UserRole; - $roles->character_id = $charId; - $roles->role = $role; - $roles->save(); + $permission = new UserPermission; + $permission->character_id = $charId; + $permission->permission = $role; + $permission->save(); } /** @@ -226,13 +231,13 @@ class LoginController extends Controller private function GetRole($refreshToken, $charId) { $accountType = $this->GetAccountType($refreshToken, $charId); if($accountType == 'Guest') { - $role = 'Guest'; + $role = 'role.guest'; } else if($accountType == 'Legacy'){ - $role = 'User'; + $role = 'role.user'; } else if($accountType == 'W4RP') { - $role = 'User'; + $role = 'role.user'; } else { - $role = 'None'; + $role = 'role.none'; } return $role; diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index b85fe8193..a74a59159 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -62,13 +62,8 @@ class RegisterController extends Controller * @param array $data * @return \App\User */ - protected function create(array $data) + protected function create() { - return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => Hash::make($data['password']), - 'character_id' => $data['characterid'], - ]); + } } diff --git a/app/Models/Admin/AllowedLogin.php b/app/Models/Admin/AllowedLogin.php index 006dc22ee..57d70ad17 100644 --- a/app/Models/Admin/AllowedLogin.php +++ b/app/Models/Admin/AllowedLogin.php @@ -1,22 +1,17 @@ registerPolicies($gate); $gate->define('isAdmin', function($user) { - //Get the roles the user has from the user_roles table and check against the gate we are creating - $check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']); - if($check[0]->role === 'Admin') { - //User has the Admin role + + $check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']); + if($check[0]-> role === 'role.admin') { return true; } else { return false; } + }); $gate->define('isDirector', function($user) { - //Get the roles the user has from the user_roles table and check against the gate we are creating - $check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']); - if($check[0]->role === 'Director') { - //User has the Director role + + $check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']); + if($check[0]-> role === 'role.director') { return true; } else { return false; } + }); $gate->define('isUser', function($user) { - //Get the roles the user has from the user_roles table and check against the gate we are creating - $check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']); - if($check[0]->role === 'User') { - //User has the User role + + $check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']); + if($check[0]-> role === 'role.user') { return true; } else { return false; } + }); $gate->define('isGuest', function($user) { - //Get the roles the user has from the user_roles table and check against the gate we are creating - $check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']); - if($check[0]->role === 'Guest') { - //User has the Guest role + + $check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']); + if($check[0]-> role === 'role.guest') { return true; } else { return false; } + }); $gate->define('isNone', function($user) { - //Get the roles the user has from the user_roles table and check against the gate we are creating - $check = UserRole::where('character_id', auth()->user()->character_id)->get(['role']); - if($check[0]->role === 'None') { - //User has no role + + $check = UserPermission::where('character_id', auth()->user()->character_id)->get(['role']); + if($check[0]-> role === 'role.none') { return true; } else { return false; diff --git a/database/migrations/2019_01_08_015340_drop_users_role_column.php b/database/migrations/2019_01_08_015340_drop_users_role_column.php new file mode 100644 index 000000000..f96c71304 --- /dev/null +++ b/database/migrations/2019_01_08_015340_drop_users_role_column.php @@ -0,0 +1,32 @@ +dropColumn('role'); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/database/migrations/2019_01_08_025935_create_allowed_logins_table.php b/database/migrations/2019_01_08_025935_create_allowed_logins_table.php new file mode 100644 index 000000000..71bac9020 --- /dev/null +++ b/database/migrations/2019_01_08_025935_create_allowed_logins_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->string('entity_id'); + $table->string('entity_type'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('allowed_logins'); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 77dff21bb..783214e88 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -9,8 +9,8 @@ return array( 'App\\Console\\Commands\\CalculateMarketTax' => $baseDir . '/app/Console/Commands/calculatemarkettax.php', 'App\\Console\\Commands\\CorpJournal' => $baseDir . '/app/Console/Commands/corpJournal.php', 'App\\Console\\Commands\\DumpFleets' => $baseDir . '/app/Console/Commands/dumpFleets.php', - 'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/getCorps.php', - 'App\\Console\\Commands\\GetLogisticsContracts' => $baseDir . '/app/Console/Commands/getLogisticContracts.php', + 'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/GetCorps.php', + 'App\\Console\\Commands\\GetLogisticsContracts' => $baseDir . '/app/Console/Commands/GetLogisticContracts.php', 'App\\Console\\Commands\\SendMail' => $baseDir . '/app/Console/Commands/sendmail.php', 'App\\Console\\Commands\\UpdateMoonPricing' => $baseDir . '/app/Console/Commands/UpdateMoonPricing.php', 'App\\Console\\Commands\\holdingfinances' => $baseDir . '/app/Console/Commands/holdingfinances.php', @@ -67,6 +67,7 @@ return array( 'App\\Library\\SeatHelper' => $baseDir . '/app/Library/SeatHelper.php', 'App\\Library\\Structures\\JumpBridgeFuel' => $baseDir . '/app/Library/Structures/JumpBridgeFuel.php', 'App\\Library\\Structures\\StructureTaxHelper' => $baseDir . '/app/Library/Structures/StructureTaxHelper.php', + 'App\\Models\\Admin\\AllowedLogin' => $baseDir . '/app/Models/Admin/AllowedLogin.php', 'App\\Models\\Character\\CharacterToCorporation' => $baseDir . '/app/Models/Charcter/CharacterToCorporation.php', 'App\\Models\\Config' => $baseDir . '/app/Models/Config.php', 'App\\Models\\Corporation\\AllianceCorp' => $baseDir . '/app/Models/Corporation/AllianceCorp.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index dfe08d33d..1aa1cd142 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -463,8 +463,8 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Console\\Commands\\CalculateMarketTax' => __DIR__ . '/../..' . '/app/Console/Commands/calculatemarkettax.php', 'App\\Console\\Commands\\CorpJournal' => __DIR__ . '/../..' . '/app/Console/Commands/corpJournal.php', 'App\\Console\\Commands\\DumpFleets' => __DIR__ . '/../..' . '/app/Console/Commands/dumpFleets.php', - 'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/getCorps.php', - 'App\\Console\\Commands\\GetLogisticsContracts' => __DIR__ . '/../..' . '/app/Console/Commands/getLogisticContracts.php', + 'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/GetCorps.php', + 'App\\Console\\Commands\\GetLogisticsContracts' => __DIR__ . '/../..' . '/app/Console/Commands/GetLogisticContracts.php', 'App\\Console\\Commands\\SendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php', 'App\\Console\\Commands\\UpdateMoonPricing' => __DIR__ . '/../..' . '/app/Console/Commands/UpdateMoonPricing.php', 'App\\Console\\Commands\\holdingfinances' => __DIR__ . '/../..' . '/app/Console/Commands/holdingfinances.php', @@ -521,6 +521,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Library\\SeatHelper' => __DIR__ . '/../..' . '/app/Library/SeatHelper.php', 'App\\Library\\Structures\\JumpBridgeFuel' => __DIR__ . '/../..' . '/app/Library/Structures/JumpBridgeFuel.php', 'App\\Library\\Structures\\StructureTaxHelper' => __DIR__ . '/../..' . '/app/Library/Structures/StructureTaxHelper.php', + 'App\\Models\\Admin\\AllowedLogin' => __DIR__ . '/../..' . '/app/Models/Admin/AllowedLogin.php', 'App\\Models\\Character\\CharacterToCorporation' => __DIR__ . '/../..' . '/app/Models/Charcter/CharacterToCorporation.php', 'App\\Models\\Config' => __DIR__ . '/../..' . '/app/Models/Config.php', 'App\\Models\\Corporation\\AllianceCorp' => __DIR__ . '/../..' . '/app/Models/Corporation/AllianceCorp.php',