diff --git a/.env.example b/.env.example index ef96f03..88e78d5 100644 --- a/.env.example +++ b/.env.example @@ -38,3 +38,5 @@ EVEONLINE_CLIENT_SECRET=null EVEONLINE_REDIRECT=null EVEONLINE_USER_AGENT='description' EVEONLINE_PRIMARY_CHAR=null + +FIRST_ADMIN_CHAR_ID=null diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 0664c08..2142cd2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,7 +28,7 @@ class Kernel extends ConsoleKernel // ->hourly(); //Horizon Graph Schedule - $schedule->command('horizon:snapshot')->everyFiveMinutes(); + //$schedule->command('horizon:snapshot')->everyFiveMinutes(); } /** diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 7aabdfa..c96a179 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -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'; diff --git a/app/Jobs/ProcessSendEveMailJob.php b/app/Jobs/ProcessSendEveMailJob.php deleted file mode 100644 index 288a54d..0000000 --- a/app/Jobs/ProcessSendEveMailJob.php +++ /dev/null @@ -1,119 +0,0 @@ -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); - } -} - -?> diff --git a/app/Models/Jobs/JobSendEveMail.php b/app/Models/Jobs/JobSendEveMail.php deleted file mode 100644 index f8cc137..0000000 --- a/app/Models/Jobs/JobSendEveMail.php +++ /dev/null @@ -1,27 +0,0 @@ -