updated some backend logic
This commit is contained in:
@@ -76,7 +76,7 @@ class GetAssetsCommand extends Command
|
||||
$assetScope = $esiHelper->HaveEsiScope($config['primary'], 'esi-assets.read_corporation_assets.v1');
|
||||
|
||||
if($assetScope == false) {
|
||||
Log::critical("Scope check for esi failed.");
|
||||
Log::critical("Scope check for esi-assets.read_corporation_assets.v1 failed.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -87,12 +87,12 @@ class GetAssetsCommand extends Command
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
|
||||
$token = $esiHelper->GetRefreshToken($charId);
|
||||
//Create the authentication container
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
$esi = new Eseye($authentication);
|
||||
|
||||
@@ -75,7 +75,7 @@ class GetEveContractsCommand extends Command
|
||||
$contractScope = $esiHelper->HaveEsiScope($charId, 'esi-contracts.read_corporation_contracts.v1');
|
||||
|
||||
if($contractScope == false) {
|
||||
Log::critical('Scope check for esi contracts failed.');
|
||||
Log::critical('Scope check for esi-contracts.read_corporation_contracts.v1 failed.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ class AssetHelper {
|
||||
* Get Assets By Page in order to store in the database
|
||||
*/
|
||||
public function GetAssetsByPage() {
|
||||
//Declare the variable for the esi helper
|
||||
$esiHelper = new Esi;
|
||||
|
||||
// Disable all caching by setting the NullCache as the
|
||||
// preferred cache handler. By default, Eseye will use the
|
||||
// FileCache.
|
||||
@@ -46,12 +49,20 @@ class AssetHelper {
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
|
||||
//Check for the scope needed
|
||||
$hasScope = $esiHelper->HaveEsiScope($this->charId, 'esi-assets.read_corporation_assets.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('ESI Scope check has failed for esi-assets.read_corporation_assets.v1 for character id: ' . $this->charId);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
|
||||
@@ -46,12 +46,20 @@ class EveContractsHelper {
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
|
||||
//Check for the scope for the esi token needed
|
||||
$hasScope = $esiHelper->HaveEsiScope($this->charId, 'esi-contracts.read_corporation_contracts.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('Esi Scope check failed for esi-contracts.read_corporation_contracts.v1 for character id: ' . $this->charId);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
@@ -78,12 +86,20 @@ class EveContractsHelper {
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
|
||||
//Check if the scope is present for ESI
|
||||
$hasScope = $esiHelper->HaveEsiScope($this->charId, 'esi-contracts.read_corporation_contracts.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('Esi Scope check failed for esi-contracts.read_corporation_contracts.v1 for character id: ' . $this->charId);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id', $this->charId])->get(['refresh_token']);
|
||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
|
||||
@@ -155,23 +155,14 @@ class Esi {
|
||||
return $realDate;
|
||||
}
|
||||
|
||||
public function GetToken($charId, $scope) {
|
||||
public function GetRefreshToken($charId) {
|
||||
//Get the refresh token from the database
|
||||
$tokenCount = EsiToken::where([
|
||||
'character_id' => $charId,
|
||||
])->count();
|
||||
|
||||
//If the token is not found, then don't return it.
|
||||
if($tokenCount == 0) {
|
||||
$config = config('esi');
|
||||
|
||||
$mail = new EveMail;
|
||||
$mail->sender = $config['primary'];
|
||||
$mail->subject = 'W4RP Services - No Token Found';
|
||||
$mail->body = "Please register at https://services.w4rp.space with the scope: " . $scope;
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -179,25 +170,7 @@ class Esi {
|
||||
'character_id' => $charId,
|
||||
])->first();
|
||||
|
||||
$scope = EsiScope::where([
|
||||
'character_id' => $charId,
|
||||
'scope' => $scope,
|
||||
])->count();
|
||||
|
||||
if($scope == 0) {
|
||||
$mail = new EveMail;
|
||||
$mail->sender = $config['primary'];
|
||||
$mail->subject = 'W4RP Services - Incorrect ESI Scope';
|
||||
$mail->body = "Please register on https://services.w4rp.space with the scope: " . $scope;
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
|
||||
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
|
||||
|
||||
return null;
|
||||
} else {
|
||||
return $token->refresh_token;
|
||||
}
|
||||
return $token->refresh_token;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,12 @@ class FinanceHelper {
|
||||
$pi_items = $this->GetPIMaterialsArray();
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('Esi scope check for esi-wallet.read_corporation_wallets.v1 has failed for character id: ' . $hcarId);
|
||||
return null;
|
||||
}
|
||||
$token = $esiHelper->GetRefreshToken($charId);
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -107,7 +112,12 @@ class FinanceHelper {
|
||||
$lookups = new LookupHelper;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
||||
return null;
|
||||
}
|
||||
$token = $esiHelper->GetRefreshToken($charId);
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -184,7 +194,12 @@ class FinanceHelper {
|
||||
$esiHelper = new Esi();
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
$hasScope = $esiHelper->HaveScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('Esi Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
||||
return null;
|
||||
}
|
||||
$token = $esiHelper->GetRefreshToken($charId);
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -279,7 +294,12 @@ class FinanceHelper {
|
||||
$lookups = new LookupHelper;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($hasScope == false) {
|
||||
Log::critical('Esi Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
||||
return null;
|
||||
}
|
||||
$token = $esiHelper->GetRefreshToken($charId);
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user