updating login controller

This commit is contained in:
2019-11-16 22:20:01 -06:00
parent 260a5d5890
commit 2a56300470
5 changed files with 34 additions and 168 deletions

View File

@@ -38,3 +38,5 @@ EVEONLINE_CLIENT_SECRET=null
EVEONLINE_REDIRECT=null
EVEONLINE_USER_AGENT='description'
EVEONLINE_PRIMARY_CHAR=null
FIRST_ADMIN_CHAR_ID=null

View File

@@ -28,7 +28,7 @@ class Kernel extends ConsoleKernel
// ->hourly();
//Horizon Graph Schedule
$schedule->command('horizon:snapshot')->everyFiveMinutes();
//$schedule->command('horizon:snapshot')->everyFiveMinutes();
}
/**

View File

@@ -123,23 +123,23 @@ class LoginController extends Controller
//If the owner has changed, then update their roles and permissions
if($this->OwnerHasChanged($authUser->owner_hash, $eve_user->owner_hash)) {
//Get the right role for the user
$role = $this->GetRole(null, $eve_user->id);
$role = $this->GetRole($eve_user->id);
//Set the role for the user
$this->SetRole($role, $eve_user->id);
$this->UpdateRole($eve_user->id, $role);
//Update the user information never the less.
$this->UpdateUser($eve_user, $role);
$this->UpdateUser($eve_user);
//Update the user's roles and permission
$this->UpdatePermission($eve_user, $role);
$this->UpdatePermission($eve_user->id);
}
//Return the user to the calling auth function
return $authUser;
} else {
//Get the role for the character to be stored in the database
$role = $this->GetRole(null, $eve_user->id);
$role = $this->GetRole($eve_user->id);
//Create the user account
$user = $this->CreateNewUser($eve_user);
//Set the role for the user
$this->SetRole($role, $eve_user->id);
$this->SetRole($eve_uer->id, $role);
//Create a user account
return $user;
}
@@ -179,24 +179,33 @@ class LoginController extends Controller
}
/**
* Update user permission
* Remove user permission(s)
*/
private function UpdatePermission($eve_user, $role) {
private function RemovePermission($charId) {
//Remove the user's permissions
UserPermission::where(['character_id' => $eve_user->id])->delete();
$perm = new UserPermission();
$perm->character_id = $eve_user->id;
$perm->permission = $role;
$perm->save();
}
/**
* Update user role
*/
private function UpdateRole($charId, $role) {
//Delete the user's current role
UserRole::where(['character_id'=> $charId])->delete();
//Add the user's new role
UserRole::insert([
'character_id'=> $charId,
'role'=> $role,
]);
}
/**
* Update the user
*/
private function UpdateUser($eve_user, $role) {
private function UpdateUser($eve_user) {
User::where('character_id', $eve_user->id)->update([
'avatar' => $eve_user->avatar,
'owner_hash' => $eve_user->owner_hash,
'role' => $role,
]);
}
@@ -223,7 +232,7 @@ class LoginController extends Controller
* @param role
* @param charId
*/
private function SetRole($role, $charId) {
private function SetRole($charId, $role) {
$permission = new UserRole;
$permission->character_id = $charId;
$permission->role = $role;
@@ -268,13 +277,11 @@ class LoginController extends Controller
* @param refreshToken
* @param charId
*/
private function GetRole($refreshToken, $charId) {
//Set caching to null
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
private function GetRole($charId) {
//Setup the user array
$haulers = AllowedLogin::where(['login_type' => 'Hauler'])->pluck('entity_id')->toArray();
$allowedUsers = AllowedLogin::where(['login_type' => 'User'])->pluck('entity_id')->toArray();
$allowedAdmins = array(env('FIRST_ADMIN_CHAR_ID'));
// Instantiate a new ESI instance
$esi = new Eseye();
@@ -285,7 +292,10 @@ class LoginController extends Controller
]);
if(isset($character_info->corporation_id)) {
if(in_array($character_info->corporation_id, $haulers)) {
if(in_array($charId, $allowedAdmins)){
$role = 'Admin';
}
else if(in_array($character_info->corporation_id, $allowedUsers)) {
$role = 'User';
} else {
$role = 'Guest';

View File

@@ -1,119 +0,0 @@
<?php
namespace App\Jobs;
/**
* This is just an example of how to create a job and send eve mails with said job.
*/
//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

@@ -1,27 +0,0 @@
<?php
namespace App\Models\Jobs;
/**
* This model is an example of how to create a model for a job for redis.
* Note the Model requires no table to be defined as the job doesn't use a table,
* but it uses the redis queue for the job.
*/
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',
];
}