From a7d3bbb858e78e56a0c9109913e8d6d90eaf12f0 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Tue, 22 Oct 2019 02:40:39 -0500 Subject: [PATCH] added purge user command --- app/Console/Commands/Users/PurgeUsers.php | 147 ++++++++++++++++++++++ app/Console/Kernel.php | 3 + app/Library/Esi/Esi.php | 16 +++ 3 files changed, 166 insertions(+) create mode 100644 app/Console/Commands/Users/PurgeUsers.php diff --git a/app/Console/Commands/Users/PurgeUsers.php b/app/Console/Commands/Users/PurgeUsers.php new file mode 100644 index 000000000..25e9e82c8 --- /dev/null +++ b/app/Console/Commands/Users/PurgeUsers.php @@ -0,0 +1,147 @@ +setQueryString([ + 'datasource' => 'tranquility', + ])->invoke('get', '/status/'); + } catch(RequestFailedException $e) { + return; + } + + //Get all of the users from the database + $users = User::all(); + + //Get the allowed logins + $legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray(); + $renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray(); + + //Cycle through all of the users, and either update their role, or delete them. + foreach($users as $user) { + //Set the fail bit to false + $failed = false; + + //Get the character information + try { + $character_info = $esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $user->character_id, + ]); + + $corp_info = $esi->invoke('get', '/corporations/{corporation_id/', [ + 'corporation_id' => $character_info->corporation_id, + ]); + } catch(RequestFailedException $e) { + Log::warning('Failed to get character information in purge user command for user ' . $user->character_id); + $failed = true; + } + + //If the fail bit is still false, then continue + if($failed === false) { + //Get the user's role + $role = UserRole::where(['character_id'])->first(); + + //Check if the user is allowed to login + if(isset($corp_info->alliance_id)) { + //Warped Intentions is allowed to login + if($corp_info->alliance_id == '99004116') { + //If the role is not Warped Intentions, then modify the role + if($role != 'W4RP') { + UserRole::where([ + 'character_id' => $user->character_id, + ])->update([ + 'role' => 'W4RP', + ]); + } + } else if(in_array($corp_info->alliance_id, $legacy)) { //Legacy Users + if($role != 'Legacy') { + UserRole::where([ + 'character_id' => $user->character_id, + ])->update([ + 'role' => 'Legacy', + ]); + } + } else if(in_array($corp_info->alliance_id, $renter)) { //Renter Users + if($role != 'Renter') { + UserRole::where([ + 'character_id' => $user->character_id, + ])->update([ + 'role' => 'Renter', + ]); + } + } else { + //If the user is part of no valid login group, then delete the user. + //Delete all of the permissions first + UserPermission::where([ + 'character_id' => $user->character_id, + ])->delete(); + + //Delete the user's role + UserRole::where([ + 'character_id' => $user->character_id, + ])->delete(); + + //Delete the user from the user table + User::where([ + 'character_id' => $user->character_id, + ])->delete(); + } + } + } + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index afcfd3add..bddd00282 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -58,6 +58,9 @@ class Kernel extends ConsoleKernel ->withoutOverlapping(); $schedule->command('services:CleanData') ->monthlyOn(1, '18:00'); + $schedule->command('services:PurgeUsers') + ->dailyAt('23:00') + ->withoutOverlapping(); //Horizon Graph Schedule $schedule->command('horizon:snapshot')->everyFiveMinutes(); diff --git a/app/Library/Esi/Esi.php b/app/Library/Esi/Esi.php index 01acfa854..c55992ac7 100644 --- a/app/Library/Esi/Esi.php +++ b/app/Library/Esi/Esi.php @@ -92,6 +92,21 @@ class Esi { ]); //Create the esi container $esi = new Eseye($authentication); + + try { + $character = $esi->setBody(array( + $name, + ))->invoke('post', '/universe/ids/'); + } catch(RequestFailedException $e) { + return null; + } + + if(isset($character->characters[0]->id)) { + return $character->characters[0]->id; + } else { + return null; + } + /* try { $character = $esi->setQueryString([ 'categories' => 'character', @@ -107,6 +122,7 @@ class Esi { $character = json_decode($character, true); return $character['character']; + */ } public function FindCorporationId($charId) {