trypost/app/Http/Controllers/Auth/XController.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2026-01-15 01:13:44 +00:00
<?php
declare(strict_types=1);
2026-01-15 01:13:44 +00:00
namespace App\Http\Controllers\Auth;
use App\Enums\SocialAccount\Platform as SocialPlatform;
2026-01-15 01:13:44 +00:00
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
2026-01-15 01:13:44 +00:00
use Symfony\Component\HttpFoundation\Response;
class XController extends SocialController
{
2026-01-15 17:24:39 +00:00
protected string $driver = 'x';
2026-01-15 01:13:44 +00:00
protected SocialPlatform $platform = SocialPlatform::X;
protected array $scopes = [
'tweet.read',
'tweet.write',
'users.read',
2026-01-15 17:24:39 +00:00
'media.write',
2026-01-15 01:13:44 +00:00
'offline.access',
];
public function connect(Request $request): Response|RedirectResponse
2026-01-15 01:13:44 +00:00
{
$this->ensurePlatformEnabled();
$workspace = $request->user()->currentWorkspace;
if (! $workspace) {
return redirect()->route('app.workspaces.create');
}
2026-01-15 17:24:39 +00:00
$this->authorize('manageAccounts', $workspace);
2026-01-15 01:13:44 +00:00
$existingAccount = $workspace->socialAccounts()
->where('platform', $this->platform->value)
->first();
if ($existingAccount && ! $existingAccount->isDisconnected()) {
session()->flash('flash.banner', __('accounts.flash.already_connected'));
session()->flash('flash.bannerStyle', 'danger');
return back();
2026-01-15 01:13:44 +00:00
}
return $this->redirectToProvider($request, $this->driver, $this->scopes);
2026-01-15 01:13:44 +00:00
}
public function callback(Request $request): View
2026-01-15 01:13:44 +00:00
{
return $this->handleCallback($request, $this->platform, $this->driver);
}
}