finally done a bit early for a bit
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
//use Laravel\Socialite\Contracts\User as ProviderUser;
|
||||
use Laravel\Socailiate\Two\User as ProviderUser;
|
||||
|
||||
class AuthAccountService {
|
||||
/**
|
||||
* Check if a user exists in the database, else, create and
|
||||
* return the user object.
|
||||
*
|
||||
* @param \Laravel\Socialite\Two\User $user
|
||||
*/
|
||||
public function createOrGetUser(ProviderUser $eve_user) {
|
||||
//Search for user in the database
|
||||
|
||||
|
||||
$account = AuthAccount::whereProvider('eveonline')->whereProviderUserId($eve_user->getId())->first();
|
||||
|
||||
if($account) {
|
||||
return $account->user;
|
||||
} else {
|
||||
$account = new AuthAccount([
|
||||
'name' => $user->getName(),
|
||||
'email' => null,
|
||||
'avatar' => $user->avatar,
|
||||
'owner_hash' => $user->character_owner_hash,
|
||||
'id'=> $user->getId(),
|
||||
'expiresIn' => $user->expiresIn,
|
||||
'token' => $user->token,
|
||||
'refreshToken' => $user->refreshToken,
|
||||
]);
|
||||
|
||||
$user = User::whereName($providerUser->getName())->first();
|
||||
|
||||
if(!$user) {
|
||||
$user = User::create([
|
||||
'name' => $user->getName(),
|
||||
'email' => null,
|
||||
'avatar' => $user->avatar,
|
||||
'owner_hash' => $user->character_owner_hash,
|
||||
'id'=> $user->getId(),
|
||||
'expiresIn' => $user->expiresIn,
|
||||
'token' => $user->token,
|
||||
'refreshToken' => $user->refreshToken,
|
||||
]);
|
||||
}
|
||||
|
||||
$account->user()->associate($user);
|
||||
$account->save();
|
||||
|
||||
return $user;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EsiToken extends Model
|
||||
{
|
||||
// Table Name
|
||||
protected $table = 'EsiTokens';
|
||||
|
||||
//Primary Key
|
||||
public $primaryKey = 'CharacterId';
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class User extends Authenticatable
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'avatar', 'owner_hash', 'character_id', 'expires_in', 'access_token', 'refresh_token',
|
||||
'name', 'email', 'avatar', 'owner_hash', 'character_id', 'expires_in', 'access_token', 'refresh_token', 'user_type',
|
||||
];
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
Reference in New Issue
Block a user