pre-horizon

This commit is contained in:
2019-09-28 23:54:46 -05:00
parent 10ad11d956
commit 561d1cf453
11 changed files with 372 additions and 86 deletions

View File

@@ -14,9 +14,12 @@ DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
QUEUE_DRIVER=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1

View File

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

View 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);
}
}
?>

View 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) {
}
}
?>

View File

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

View 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',
];
}

View File

@@ -9,12 +9,14 @@
"license": "MIT",
"require": {
"php": "^7.2",
"barryvdh/laravel-debugbar": "^3.2",
"eveseat/eseye": "^1.1",
"fideloper/proxy": "^4.0",
"laravel/framework": "^6.0",
"laravel/socialite": "^4.2",
"laravel/tinker": "^1.0",
"laravelcollective/html": "^6.0",
"predis/predis": "^1.1",
"twbs/bootstrap": "^4.3"
},
"require-dev": {

131
composer.lock generated
View File

@@ -4,8 +4,76 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5fb9de1acc8a170ba905235ac9fda870",
"content-hash": "e214a5d5e8b3e185b2ce92a8c2565e0f",
"packages": [
{
"name": "barryvdh/laravel-debugbar",
"version": "v3.2.8",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-debugbar.git",
"reference": "18208d64897ab732f6c04a19b319fe8f1d57a9c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/18208d64897ab732f6c04a19b319fe8f1d57a9c0",
"reference": "18208d64897ab732f6c04a19b319fe8f1d57a9c0",
"shasum": ""
},
"require": {
"illuminate/routing": "^5.5|^6",
"illuminate/session": "^5.5|^6",
"illuminate/support": "^5.5|^6",
"maximebf/debugbar": "~1.15.0",
"php": ">=7.0",
"symfony/debug": "^3|^4",
"symfony/finder": "^3|^4"
},
"require-dev": {
"laravel/framework": "5.5.x"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
},
"laravel": {
"providers": [
"Barryvdh\\Debugbar\\ServiceProvider"
],
"aliases": {
"Debugbar": "Barryvdh\\Debugbar\\Facade"
}
}
},
"autoload": {
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "PHP Debugbar integration for Laravel",
"keywords": [
"debug",
"debugbar",
"laravel",
"profiler",
"webprofiler"
],
"time": "2019-08-29T07:01:03+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
"version": "0.1",
@@ -1193,6 +1261,67 @@
],
"time": "2016-08-17T00:36:58+00:00"
},
{
"name": "maximebf/debugbar",
"version": "v1.15.0",
"source": {
"type": "git",
"url": "https://github.com/maximebf/php-debugbar.git",
"reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30e7d60937ee5f1320975ca9bc7bcdd44d500f07",
"reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"psr/log": "^1.0",
"symfony/var-dumper": "^2.6|^3.0|^4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0"
},
"suggest": {
"kriswallsmith/assetic": "The best way to manage assets",
"monolog/monolog": "Log using Monolog",
"predis/predis": "Redis storage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.14-dev"
}
},
"autoload": {
"psr-4": {
"DebugBar\\": "src/DebugBar/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maxime Bouroumeau-Fuseau",
"email": "maxime.bouroumeau@gmail.com",
"homepage": "http://maximebf.com"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Debug bar in the browser for php application",
"homepage": "https://github.com/maximebf/php-debugbar",
"keywords": [
"debug",
"debugbar"
],
"time": "2017-12-15T11:13:46+00:00"
},
{
"name": "monolog/monolog",
"version": "1.25.1",

View File

@@ -13,7 +13,7 @@ return [
|
*/
'default' => env('QUEUE_CONNECTION', 'sync'),
'default' => env('QUEUE_CONNECTION', 'redis'),
/*
|--------------------------------------------------------------------------

View File

@@ -18,7 +18,7 @@ return [
|
*/
'driver' => env('SESSION_DRIVER', 'file'),
'driver' => env('SESSION_DRIVER', 'redis'),
/*
|--------------------------------------------------------------------------

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('jobs')) {
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}