pre-horizon
This commit is contained in:
@@ -4,13 +4,21 @@ namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
//Library
|
||||
use App\Library\Contracts\ContractHelper;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('role:Uesr');
|
||||
$this->middleware('role:User');
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
|
||||
//Get the current amount of contracts availabe to the corporation for displaying on the dashboard with the relevant
|
||||
//information such as pickup and destination, jumps, and profit margin.
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
|
||||
115
app/Jobs/ProcessSendEveMailJob.php
Normal file
115
app/Jobs/ProcessSendEveMailJob.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Log;
|
||||
|
||||
//Seat stuff
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
//Models
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Esi\EsiToken;
|
||||
|
||||
class ProcessSendEveMailJob implements ShouldQueue {
|
||||
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Timeout in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Retries
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retries = 3;
|
||||
private $body;
|
||||
private $recipient;
|
||||
private $recipient_type;
|
||||
private $subject;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(EveMail $mail) {
|
||||
|
||||
$this->body = $mail->body;
|
||||
$this->recipient = $mail->recipient;
|
||||
$this->recipient_type = $mail->recipient_type;
|
||||
$this->subject = $mail->subject;
|
||||
|
||||
$this->connection = 'redis';
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
* Utilized by using ProcessSendEveMailJob::dispatch($mail);
|
||||
* The model is passed into the dispatch function, then added to the queue
|
||||
* for processing.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//Get the esi configuration
|
||||
$config = config('esi');
|
||||
|
||||
//Declare the esi helper
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Get the refresh token
|
||||
$token = $esiHelper->GetRefreshToken($config['primary']);
|
||||
//Setup the authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Attemp to send the mail
|
||||
try {
|
||||
$esi->setBody([
|
||||
'approved_cost' => 100,
|
||||
'body' => $this->body,
|
||||
'recipients' => [[
|
||||
'recipient_id' => $this->recipient,
|
||||
'recipient_type' => $this->recipient_type,
|
||||
]],
|
||||
'subject' => $this->subject,
|
||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||
'character_id'=> $config['primary'],
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
Log::warning($e);
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* The job failed to process.
|
||||
*
|
||||
* @param Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
public function failed($exception)
|
||||
{
|
||||
Log::critical($exception);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
50
app/Library/Contracts/ContractHelper.php
Normal file
50
app/Library/Contracts/ContractHelper.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Contracts;
|
||||
|
||||
//Internal Libraries
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
//Library
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
//Models
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Esi\EsiToken;
|
||||
|
||||
class ContractHelper {
|
||||
|
||||
//Variables
|
||||
private $esi;
|
||||
|
||||
//Construct
|
||||
public function __construct() {
|
||||
//Declare a helper variable we will need
|
||||
$esiHelper = new Esi;
|
||||
|
||||
// Disable all caching for esi by setting teh NullCache as the
|
||||
// preferred cache handler. By default Eseye will use the FileCache
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Get the refresh token from the database
|
||||
$token = $esiHelper->GetRefreshToken($config['primary']);
|
||||
$this->esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
}
|
||||
|
||||
public function GetNumOfContracts() {
|
||||
|
||||
}
|
||||
|
||||
public function GetContractDetails($contract) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -43,86 +43,6 @@ class Esi {
|
||||
}
|
||||
}
|
||||
|
||||
public function GetCharacterData($charId) {
|
||||
$esi = new Eseye();
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $character;
|
||||
}
|
||||
|
||||
public function GetCharacterName($charId) {
|
||||
$esi = new Eseye();
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $character->name;
|
||||
}
|
||||
|
||||
public function FindCharacterId($name) {
|
||||
$config = config('esi');
|
||||
//Create the esi authentication container
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
]);
|
||||
//Create the esi container
|
||||
$esi = new Eseye($authentication);
|
||||
try {
|
||||
$character = $esi->setQueryString([
|
||||
'categories' => 'character',
|
||||
'language' => 'en-us',
|
||||
'search' => $name,
|
||||
'strict' => 'true',
|
||||
])->invoke('get', '/search/');
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$character = json_decode($character, true);
|
||||
return $character['character'];
|
||||
}
|
||||
|
||||
public function FindCorporationId($charId) {
|
||||
$esi = new Eseye();
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $character->corporation_id;
|
||||
}
|
||||
|
||||
public function FindCorporationName($charId) {
|
||||
$esi = new Eseye();
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
|
||||
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $corporation->name;
|
||||
}
|
||||
|
||||
public function DecodeDate($date) {
|
||||
//Find the end of the date
|
||||
$dateEnd = strpos($date, "T");
|
||||
|
||||
21
app/Models/Jobs/JobSendEveMail.php
Normal file
21
app/Models/Jobs/JobSendEveMail.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Jobs;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class JobSendEveMail extends Model
|
||||
{
|
||||
//Timestamps
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = [
|
||||
'sender',
|
||||
'recipient',
|
||||
'recipient_type',
|
||||
'subject',
|
||||
'body',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user