added purge user command

This commit is contained in:
2019-10-22 02:40:39 -05:00
parent b153607e32
commit a7d3bbb858
3 changed files with 166 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
<?php
namespace App\Console\Commands;
//Internal Library
use Illuminate\Console\Command;
//Libraries
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
//Models
use App\Models\User\User;
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\User\UserPermission;
use App\Models\User\UserRole;
use App\Models\Admin\AllowedLogin;
class PurgeUsers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:PurgeUsers';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update and purge users from the database.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Setup the esi variable
$esi = new Eseye();
//Attempt to get the server status. Don't want to do anything if the server is down for some reason.
try {
$status = $esi->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();
}
}
}
}
}
}

View File

@@ -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();

View File

@@ -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) {