From cd247a22b503b445d20cd06a5499e6883416de3c Mon Sep 17 00:00:00 2001 From: Chris Mancuso Date: Sat, 21 Feb 2026 15:48:48 -0600 Subject: [PATCH] added new Socialite example to fit in with existing code. --- app/Http/Controllers/Auth/LoginController.php | 43 ++++++++++- app/Models/User.php | 4 +- app/Providers/AppServiceProvider.php | 3 + composer.json | 1 + composer.lock | 65 +++++++++++++++- .../0001_01_01_000000_create_users_table.php | 77 +++++++++++++------ routes/web.php | 13 ++++ 7 files changed, 181 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 991803a..75498fb 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -38,6 +38,47 @@ class LoginController extends Controller return redirect('/'); } + /** + * Redirect to provider's website + * + * @return param + */ + public function redirectToEveonline() { + return Socialite::driver('eveonline')->scopes(['publicData'])->redirect(); + } + + /** + * Create a new controller instance + * + * @return void + */ + public function handleEveonlineCallback() { + try { + $user = Socialite::driver('eveonline')->user(); + $findUser = User::where('character_id', $user->character_id)->first(); + + if($findUser) { + Auth::login($finduser); + return redirect()->intended('home'); + } else { + $newUser = User::updateOrCreate(['character_id' => $user->character_id], [ + 'character_name' => $user->character_name, + 'character_id' => $user->character_id, + 'token' => $user->token, + 'refresh_token' => $user->refresh_token, + 'expiresIn' => $user->expiresIn, + 'user_jwt_token' => $user->user, + ]); + + Auth::login($newUser); + + return redirect()->intended('home'); + } + } catch(Exception $e) { + dd($e->getMessage()); + } + } + /** * Redirect to the provider's website * @@ -50,7 +91,7 @@ class LoginController extends Controller * @return expiresIn * @return user (Holds jwt) */ - public function redirectToProvider() { + public function redirectToProvider_old() { //The default scope is public data for everyone due to OAuth2 Tokens //Add esi-mail.send_mail.v1 to send mails more efficiently $scopes = ['publicData', 'esi-mail.send_mail.v1']; diff --git a/app/Models/User.php b/app/Models/User.php index 749c7b7..f925eab 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -18,9 +18,11 @@ class User extends Authenticatable * @var list */ protected $fillable = [ - 'name', + 'character_id', + 'character_name', 'email', 'password', + 'character_owner_hash', ]; /** diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a6912c8..0f3087d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -28,5 +28,8 @@ class AppServiceProvider extends ServiceProvider public function boot(): void { // + Event::listen(function (\SocialiteProvider\Manager\SocialiteWasCalled $event) { + $event->extendSocialite('eveonline', \SocialiteProviders\Eveonline\Provider::class); + }); } } diff --git a/composer.json b/composer.json index 92e7897..ad59489 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "laravel/framework": "^12.0", "laravel/horizon": "^5.44", "laravel/tinker": "^2.10.1", + "laravel/ui": "^4.6", "socialiteproviders/eveonline": "^4.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index d5a5661..88208b2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9abf5d0f046d00e112328cc59a6ee96c", + "content-hash": "b238498d72621c2daf8235938fd6d8c3", "packages": [ { "name": "brick/math", @@ -1674,6 +1674,69 @@ }, "time": "2026-02-06T14:12:35+00:00" }, + { + "name": "laravel/ui", + "version": "v4.6.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/ui.git", + "reference": "7d6ffa38d79f19c9b3e70a751a9af845e8f41d88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/ui/zipball/7d6ffa38d79f19c9b3e70a751a9af845e8f41d88", + "reference": "7d6ffa38d79f19c9b3e70a751a9af845e8f41d88", + "shasum": "" + }, + "require": { + "illuminate/console": "^9.21|^10.0|^11.0|^12.0", + "illuminate/filesystem": "^9.21|^10.0|^11.0|^12.0", + "illuminate/support": "^9.21|^10.0|^11.0|^12.0", + "illuminate/validation": "^9.21|^10.0|^11.0|^12.0", + "php": "^8.0", + "symfony/console": "^6.0|^7.0" + }, + "require-dev": { + "orchestra/testbench": "^7.35|^8.15|^9.0|^10.0", + "phpunit/phpunit": "^9.3|^10.4|^11.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Ui\\UiServiceProvider" + ] + }, + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Laravel\\Ui\\": "src/", + "Illuminate\\Foundation\\Auth\\": "auth-backend/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel UI utilities and presets.", + "keywords": [ + "laravel", + "ui" + ], + "support": { + "source": "https://github.com/laravel/ui/tree/v4.6.1" + }, + "time": "2025-01-28T15:15:29+00:00" + }, { "name": "league/commonmark", "version": "2.8.0", diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..b70f002 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -11,30 +11,61 @@ return new class extends Migration */ public function up(): void { - Schema::create('users', function (Blueprint $table) { - $table->id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); + if(!Schema::hasTable('users')) { + Schema::create('users', function (Blueprint $table) { + $table->id(); + $table->string('character_id'); + $table->string('character_name'); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->string('character_owner_hash'); + $table->string('token'); + $table->string('refresh_token'); + $table->integer('expiresIn'); + $table->string('user_jwt_token'); + $table->rememberToken(); + $table->timestamps(); + }); + } - Schema::create('password_reset_tokens', function (Blueprint $table) { - $table->string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); + if(!Schema::hasTable('password_reset_tokens')) { + Schema::create('password_reset_tokens', function (Blueprint $table) { + $table->string('email')->primary(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + } - Schema::create('sessions', function (Blueprint $table) { - $table->string('id')->primary(); - $table->foreignId('user_id')->nullable()->index(); - $table->string('ip_address', 45)->nullable(); - $table->text('user_agent')->nullable(); - $table->longText('payload'); - $table->integer('last_activity')->index(); - }); + if(!Schema::hasTable('sessions')) { + Schema::create('sessions', function (Blueprint $table) { + $table->string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); + } + + if(!Schema::hasTable('esi_token')) { + Schema::create('esi_token', function (Blueprint $table) { + $table->id(); + $table->string('character_id'); + $table->string('token'); + $table->string('refresh_token'); + $table->integer('expiresIn'); + $table->string('user_jwt_token'); + }); + } + + if(!Schema::hasTable('esi_scopes')) { + Schema::create('esi_scopes', function (Blueprint $table) { + $table->id(); + $table->string('character_id'); + $table->string('scope'); + }); + } } /** @@ -45,5 +76,7 @@ return new class extends Migration Schema::dropIfExists('users'); Schema::dropIfExists('password_reset_tokens'); Schema::dropIfExists('sessions'); + Schema::dropIfExists('esi_token'); + Schema::dropIfExists('esi_scopes'); } }; diff --git a/routes/web.php b/routes/web.php index 86a06c5..af9bada 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,19 @@ use Illuminate\Support\Facades\Route; +use App\Http\Controllers\Auth\LoginController; +use App\Http\Controllers\Dashboard\DashboardController; + Route::get('/', function () { return view('welcome'); }); + +Auth::routes(); + +Route::get('/home', [App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard'); + +Route::controller(LoginController::class)->group(function(){ + Route::get('auth/eveonline', 'redirectToEve')->('auth.eveonline'); + Route::get('auth/eveonline/callback', 'handleEveonlineCallback'); +}); +