esi tokens and scopes

This commit is contained in:
2018-11-05 12:17:58 -06:00
parent 9ca1415e10
commit 5ee020f670

View File

@@ -105,6 +105,36 @@ class LoginController extends Controller
'refresh_token' => $eve_user->refreshToken,
'scopes' => $eve_user->user['Scopes'],
]);
//See if we have an access token for the user.
//If we have a token update the token, if not create an entry into the database
$token = EsiToken::where('character_id', $eve_user->id)->first();
if($token) {
//Update the ESI Token
DB::table('EsiTokens')->where('character_id', $eve_user->id)->update([
'character_id' => $eve_user->getId(),
'access_token' => $eve_user->token,
'refresh_token' => $eve_user->token,
'expires_in' => $eve_user->expiresIn,
]);
} else {
//Save the ESI Token in the database
DB::table('EsiTokens')->insert([
'character_id' => $eve_user->getId(),
'access_token' => $eve_user->token,
'refresh_token' => $eve_user->token,
'expires_in' => $eve_user->expiresIn,
]);
}
//After creating the token, we need to update the table for scopes
//First we look for all the scopes, then if need be add entries or delete entries from the database
EsiScopes::where('character_id', $eve_user->id)->delete();
$scopes = explode(' ', $eve_user->user['Scopes']);
foreach($scopes as $scope) {
DB::table('EsiScopes')->insert([
'character_id' => $eve_user->getId(),
'scope' => $scope,
])
}
} else {
DB::table('users')->where('character_id', $eve_user->id)->update([
'name' => $eve_user->getName(),