created mail helper and modified moon mailer
This commit is contained in:
@@ -16,7 +16,7 @@ use Commands\Library\CommandHelper;
|
||||
//Models
|
||||
use App\Models\Flex\FlexStructure;
|
||||
use App\Models\Mail\SentMail;
|
||||
use App\Models\Mail\EveMail;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
|
||||
class FlexStructureCommand extends Command
|
||||
{
|
||||
@@ -93,7 +93,7 @@ class FlexStructureCommand extends Command
|
||||
$body += "Warped Intentions Leadership<br>";
|
||||
|
||||
//Dispatch the mail job
|
||||
$mail = new EveMail;
|
||||
$mail = new JobSendEveMail;
|
||||
$mail->sender = $config['primary'];
|
||||
$mail->subject = "Warped Intentions Flex Structures Payment Due for " . $today->englishMonth;
|
||||
$mail->body = $body;
|
||||
|
||||
@@ -20,7 +20,6 @@ use App\Models\Moon\Moon;
|
||||
use App\Models\MoonRent\MoonRental;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
use App\Models\Mail\SentMail;
|
||||
use App\Models\Mail\EveMail;
|
||||
|
||||
class MoonMailerCommand extends Command
|
||||
{
|
||||
@@ -113,8 +112,6 @@ class MoonMailerCommand extends Command
|
||||
//Increment the delay for the mail to not hit rate limits
|
||||
$delay += 30;
|
||||
|
||||
$this->SendMail($mail);
|
||||
|
||||
//Update the moon as not being paid for the next month?
|
||||
foreach($rentals as $rental) {
|
||||
$previous = new Carbon($rental->Paid_Until);
|
||||
|
||||
@@ -19,7 +19,6 @@ use App\Models\User\UserPermission;
|
||||
use App\Models\Contracts\Contract;
|
||||
use App\Models\Contracts\Bid;
|
||||
use App\Models\Contracts\AcceptedBid;
|
||||
use App\Models\Mail\EveMail;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
|
||||
class ContractAdminController extends Controller
|
||||
@@ -137,7 +136,6 @@ class ContractAdminController extends Controller
|
||||
]);
|
||||
|
||||
//Declare class variables
|
||||
$mail = new Mail;
|
||||
$tries = 1;
|
||||
|
||||
//Get the esi config
|
||||
@@ -156,7 +154,7 @@ class ContractAdminController extends Controller
|
||||
$body .= 'Sincerely,<br>Spatial Forces Contracting Department';
|
||||
|
||||
//Setup the mail job
|
||||
$mail = new EveMail;
|
||||
$mail = new JobSendEveMail;
|
||||
$mail->subject = $subject;
|
||||
$mail->recipient_type = 'character';
|
||||
$mail->recipient = $bid['character_id'];
|
||||
@@ -195,7 +193,7 @@ class ContractAdminController extends Controller
|
||||
|
||||
//Cycle through the users with the correct permission and send a mail to go out with the queue system.
|
||||
foreach($users as $user) {
|
||||
$mail = new EveMail;
|
||||
$mail = new JobSendEveMail;
|
||||
$mail->sender = $config['primary'];
|
||||
$mail->subject = 'New Alliance Contract Available';
|
||||
$mail->recipient = $user['character_id'];
|
||||
|
||||
@@ -18,7 +18,6 @@ use App\Library\Lookups\LookupHelper;
|
||||
use App\Models\Logistics\AnchorStructure;
|
||||
use App\Models\Mail\SentMail;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
use App\Models\Mail\EveMail;
|
||||
|
||||
class StructureRequestController extends Controller
|
||||
{
|
||||
|
||||
@@ -13,11 +13,12 @@ use Log;
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
|
||||
//Models
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\Mail\EveMail;
|
||||
use App\Models\Jobs\JobStatus;
|
||||
use App\Models\Mail\SentMail;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
@@ -78,7 +79,7 @@ class ProcessSendEveMailJob implements ShouldQueue
|
||||
$config = config('esi');
|
||||
|
||||
//Retrieve the token for main character to send mails from
|
||||
$token = EsiToken::where(['character_id'=> $this->sender])->first();
|
||||
$token = $esiHelper->GetRefreshToken($config['primary']);
|
||||
|
||||
//Create the ESI authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
@@ -10,7 +10,6 @@ use Carbon\Carbon;
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
use App\Models\Mail\EveMail;
|
||||
|
||||
//Jobs
|
||||
use App\Jobs\ProcessSendEveMailJob;
|
||||
@@ -43,14 +42,14 @@ class Esi {
|
||||
$check = EsiScope::where(['character_id' => $charId, 'scope' => $scope])->count();
|
||||
if($check == 0) {
|
||||
//Compose a mail to send to the user if the scope is not found
|
||||
$mail = new EveMail;
|
||||
$mail = new JobSendEveMail;
|
||||
$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));
|
||||
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(5);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ use App\Jobs\ProcessSendEveMailJob;
|
||||
//Models
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Mail\EveMail;
|
||||
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* W4RP Services
|
||||
* GNU Public License
|
||||
*/
|
||||
|
||||
namespace App\Library\Mail\Helper;
|
||||
|
||||
//Internal Library
|
||||
use Log;
|
||||
|
||||
//Job
|
||||
use App\Jobs\ProcessSendEveMailJob;
|
||||
|
||||
//Models
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\Esi\EsiScope;
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use App\Library\Lookups\LookupHelper;
|
||||
|
||||
//Seat Stuff
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
|
||||
class EveMailHelper {
|
||||
|
||||
public function SendEveMail($sender, $subject, $body, $recipient, $rType) {
|
||||
//Get the esi config from the environment file
|
||||
$config = config('esi');
|
||||
|
||||
//Declare the ESI Helper
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Check for the correct scope
|
||||
if(!$esiHelper->HaveEsiScope($sender, 'esi-mail.send_mail.v1')) {
|
||||
Log::critical('Could not find correct scope for the token for the mailer.');
|
||||
return null;
|
||||
}
|
||||
|
||||
//Retrieve token from from the database for the sender
|
||||
$token = $esiHelper->GetRefreshToken($sender);
|
||||
|
||||
//Create the ESI authentication container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||
|
||||
//Set caching to null
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Attempt 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'=> $this->sender,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
Log::warning($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user