Skip to content

Commit

Permalink
Merge branch 'dev' into addIVAOOauth
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/Http/Controllers/Auth/OAuthController.php
#	app/Http/Resources/User.php
#	app/Models/User.php
#	app/Providers/EventServiceProvider.php
#	composer.json
#	composer.lock
#	config/services.php
#	resources/views/layouts/default/auth/login.blade.php
#	resources/views/layouts/default/profile/index.blade.php
#	tests/OAuthTest.php
  • Loading branch information
arthurpar06 committed Jul 1, 2024
2 parents 7ea7b91 + d39eb77 commit ea0e83f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('vatsim_id')->default('')->after('discord_private_channel_id');
});
}

public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('vatsim_id');
});
}
};
5 changes: 5 additions & 0 deletions app/Http/Controllers/Auth/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function redirectToProvider(string $provider): RedirectResponse
return Socialite::driver('discord')->scopes(['identify'])->redirect();
case 'ivao':
return Socialite::driver('ivao')->redirect();
case 'vatsim':
return Socialite::driver('vatsim')->scopes(['email'])->redirect();
default:
abort(404);
}
Expand All @@ -56,6 +58,9 @@ public function handleProviderCallback(string $provider, Request $request): View
case 'ivao':
$providerUser = Socialite::driver('ivao')->user();
break;
case 'vatsim':
$providerUser = Socialite::driver('vatsim')->user();
break;
default:
abort(404);
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function toArray($request)
'name_private' => $this->name_private,
'avatar' => $this->resolveAvatarUrl(),
'discord_id' => $this->discord_id,
'vatsim_id' => $this->vatsim_id,
'ivao_id' => $this->ivao_id,
'rank_id' => $this->rank_id,
'home_airport' => $this->home_airport_id,
Expand Down
3 changes: 3 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* @property Journal journal
* @property int rank_id
* @property string discord_id
* @property string vatsim_id
* @property string ivao_id
* @property int state
* @property string last_ip
Expand Down Expand Up @@ -98,6 +99,7 @@ class User extends Authenticatable implements LaratrustUser, MustVerifyEmail
'rank_id',
'discord_id',
'discord_private_channel_id',
'vatsim_id',
'ivao_id',
'api_key',
'country',
Expand Down Expand Up @@ -174,6 +176,7 @@ class User extends Authenticatable implements LaratrustUser, MustVerifyEmail
'transfer_time',
'created_at',
'state',
'vatsim_id',
'ivao_id',
];

Expand Down
1 change: 1 addition & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class EventServiceProvider extends ServiceProvider
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
\SocialiteProviders\Discord\DiscordExtendSocialite::class.'@handle',
\SocialiteProviders\Ivao\IvaoExtendSocialite::class.'@handle',
\SocialiteProviders\Vatsim\VatsimExtendSocialite::class.'@handle',
],

];
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"league/flysystem-sftp-v3": "^3.0",
"nikolaposa/version": "^4.2",
"spatie/laravel-activitylog": "^4.7",
"socialiteproviders/vatsim": "^5.0",
"socialiteproviders/ivao": "^4.0"
},
"require-dev": {
Expand Down
54 changes: 53 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
'avatar_default_extension' => env('DISCORD_EXTENSION_DEFAULT', 'png'), // only pick from jpg, png, webp
],

'vatsim' => [
'enabled' => env('VATSIM_OAUTH_ENABLED', false),
'client_id' => env('VATSIM_CLIENT_ID'),
'client_secret' => env('VATSIM_CLIENT_SECRET'),
'redirect' => '/oauth/vatsim/callback',

// For local development only
'test' => env('VATSIM_TEST', false),
],

'ivao' => [
'enabled' => env('IVAO_OAUTH_ENABLED', false),
'client_id' => env('IVAO_CLIENT_ID'),
Expand Down
6 changes: 6 additions & 0 deletions resources/views/layouts/default/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class="form-control"
@lang('auth.loginwith', ['provider' => 'IVAO'])
</a>
@endif

@if(config('services.vatsim.enabled'))
<a href="{{ route('oauth.redirect', ['provider' => 'vatsim']) }}" class="btn btn-round btn-lg btn-block" style="background-color:#29B473;">
@lang('auth.loginwith', ['provider' => 'VATSIM'])
</a>
@endif
<button class="btn btn-primary btn-round btn-lg btn-block">@lang('common.login')</button>
</div>
<div class="pull-left">
Expand Down
6 changes: 6 additions & 0 deletions resources/views/layouts/default/profile/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<a href="{{ route('oauth.logout', ['provider' => 'ivao']) }}" class="btn" style="background-color:#0d2c99;">Unlink IVAO Account</a>
@endif

@if(config('services.vatsim.enabled') && !$user->vatsim_id)
<a href="{{ route('oauth.redirect', ['provider' => 'vatsim']) }}" class="btn" style="background-color:#29B473;">Link VATSIM Account</a>
@elseif(config('services.vatsim.enabled'))
<a href="{{ route('oauth.logout', ['provider' => 'vatsim']) }}" class="btn" style="background-color:#29B473;">Unlink VATSIM Account</a>
@endif

<a href="{{ route('frontend.profile.regen_apikey') }}" class="btn btn-warning"
onclick="return confirm('Are you sure? This will reset your API key!')">@lang('profile.newapikey')</a>
&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion tests/OAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
final class OAuthTest extends TestCase
{
/** @var array|string[] The drivers we want to test */
protected array $drivers = ['discord', 'ivao'];
protected array $drivers = ['discord', 'ivao', 'vatsim'];

protected function setUp(): void
{
Expand Down

0 comments on commit ea0e83f

Please sign in to comment.