finally done a bit early for a bit

This commit is contained in:
2018-10-15 22:57:35 -05:00
parent ed4aa6d76a
commit 46fd169b60
4 changed files with 49 additions and 76 deletions

View File

@@ -8,6 +8,11 @@ use Socialite;
use Auth;
use App\User;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
class LoginController extends Controller
{
/*
@@ -71,7 +76,9 @@ class LoginController extends Controller
if($authUser) {
return $authUser;
} else {
//Get what type of account the user should have
$accountType = getAccountType($eve_user->refreshToken, $eve_user->getId());
return User::create([
'name' => $eve_user->getName(),
'email' => null,
@@ -81,7 +88,47 @@ class LoginController extends Controller
'expires_in' => $eve_user->expiresIn,
'access_token' => $eve_user->token,
'refresh_token' => $eve_user->refreshToken,
'user_type' => $accountType,
]);
}
}
private function getAccountType($refreshToken, $charId) {
//Set caching to null
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Prepare an authentication container for ESI
$authentication = new EsiAuthentication([
'client_id' => env('EVEONLINE_CLIENT_ID'),
'secret' => env('EVEONLINE_CLIENT_SECRET'),
'refresh_token' => $refreshToken,
]);
// Instantiate a new ESI instance
$esi = new Eseye($authentication);
//Get the character information
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
//Get the corporation information
$corp_info = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $character_info->corporation_id,
]);
//Get the alliance information
$alliance_info = $esi->invoke('get','/alliances/{alliance_id}/', [
'alliance_id' => $corp_info->alliance_id,
]);
if($alliance_info->alliance_id == '99004116') {
return 'W4RP';
} else if(in_array($alliance_info->alliance_id, array(99006297, 498125261, 99003214, 99004136, 9900237, 99001657, 99006069, 99001099, 99003838))) {
return 'Legacy';
} else {
return 'Guest';
}
}
}