2026-01-18 16:33:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
Settings pages:
- Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections)
- Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal
- Add workspace logo upload/delete routes and controller methods
- Translate all hardcoded strings in Workspace.vue modals
Language system:
- Drop languages table, replace language_id FK with locale string column on users
- Create config/languages.php for available languages and default locale
- Add Spanish (es) translations (13 files)
- Simplify HandleInertiaRequests, ProfileController, RegisteredUserController
Code quality:
- Add declare(strict_types=1) to all PHP files
- Fix MastodonPublisher using wrong attribute (filename -> original_filename)
- Fix HasMediaTest for new has_photo/photo_url accessors
- Fix PublishToSocialPlatformTest type error revealed by strict_types
- Remove orphaned Language model from AppServiceProvider morph map
- Update User TypeScript interface (has_photo, photo_url, locale)
- Eager load media relation on workspaces to prevent N+1
- Add 8 new tests for workspace logo upload/delete
- Update workspace settings test to assert members/invitations props
All 710 tests passing.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-18 16:33:54 +00:00
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
|
|
use App\Enums\SocialAccount\Platform as SocialPlatform;
|
|
|
|
|
use App\Enums\SocialAccount\Status;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Inertia\Response;
|
|
|
|
|
|
|
|
|
|
class BlueskyController extends SocialController
|
|
|
|
|
{
|
|
|
|
|
protected SocialPlatform $platform = SocialPlatform::Bluesky;
|
|
|
|
|
|
|
|
|
|
public function connect(Request $request): Response|RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$this->ensurePlatformEnabled();
|
|
|
|
|
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.workspaces.create');
|
2026-01-18 16:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('manageAccounts', $workspace);
|
2026-04-14 21:44:47 +00:00
|
|
|
$this->ensureSocialAccountLimit($workspace);
|
2026-01-18 16:33:54 +00:00
|
|
|
|
|
|
|
|
return Inertia::render('accounts/BlueskyConnect', [
|
|
|
|
|
'errors' => session('errors')?->getBag('default')?->toArray() ?? [],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(Request $request): View|RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$this->ensurePlatformEnabled();
|
|
|
|
|
|
|
|
|
|
$request->validate([
|
|
|
|
|
'identifier' => 'required|string',
|
|
|
|
|
'password' => 'required|string|min:3',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.workspaces.create');
|
2026-01-18 16:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('manageAccounts', $workspace);
|
|
|
|
|
|
|
|
|
|
$service = 'https://bsky.social';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Authenticate with Bluesky
|
|
|
|
|
$response = Http::post("{$service}/xrpc/com.atproto.server.createSession", [
|
|
|
|
|
'identifier' => $request->identifier,
|
|
|
|
|
'password' => $request->password,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($response->failed()) {
|
|
|
|
|
Log::error('Bluesky authentication failed', [
|
|
|
|
|
'status' => $response->status(),
|
|
|
|
|
'body' => $response->body(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$errorMessage = 'Invalid credentials';
|
|
|
|
|
$body = $response->json();
|
|
|
|
|
if (isset($body['message'])) {
|
|
|
|
|
$errorMessage = $body['message'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return back()->withErrors(['password' => $errorMessage]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $response->json();
|
|
|
|
|
|
|
|
|
|
// Get profile
|
2026-03-31 03:40:18 +00:00
|
|
|
$profileResponse = Http::withToken(data_get($data, 'accessJwt'))
|
2026-01-18 16:33:54 +00:00
|
|
|
->get("{$service}/xrpc/app.bsky.actor.getProfile", [
|
2026-03-31 03:40:18 +00:00
|
|
|
'actor' => data_get($data, 'did'),
|
2026-01-18 16:33:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$profile = $profileResponse->successful() ? $profileResponse->json() : [];
|
|
|
|
|
|
2026-03-31 03:40:18 +00:00
|
|
|
$avatarPath = data_get($profile, 'avatar') ? uploadFromUrl(data_get($profile, 'avatar')) : null;
|
2026-01-18 16:33:54 +00:00
|
|
|
|
2026-04-14 22:48:35 +00:00
|
|
|
// Create new account
|
|
|
|
|
$workspace->socialAccounts()->create([
|
2026-01-18 16:33:54 +00:00
|
|
|
'platform' => $this->platform->value,
|
2026-03-31 03:40:18 +00:00
|
|
|
'platform_user_id' => data_get($data, 'did'),
|
|
|
|
|
'username' => data_get($data, 'handle'),
|
|
|
|
|
'display_name' => data_get($profile, 'displayName', data_get($data, 'handle')),
|
2026-01-18 16:33:54 +00:00
|
|
|
'avatar_url' => $avatarPath,
|
2026-03-31 03:40:18 +00:00
|
|
|
'access_token' => data_get($data, 'accessJwt'),
|
|
|
|
|
'refresh_token' => data_get($data, 'refreshJwt'),
|
2026-01-18 16:33:54 +00:00
|
|
|
'token_expires_at' => now()->addHours(2),
|
2026-04-14 22:48:35 +00:00
|
|
|
'status' => Status::Connected,
|
2026-01-18 16:33:54 +00:00
|
|
|
'meta' => [
|
|
|
|
|
'service' => $service,
|
|
|
|
|
'identifier' => $request->identifier,
|
|
|
|
|
'password' => encrypt($request->password),
|
|
|
|
|
],
|
2026-04-14 22:48:35 +00:00
|
|
|
]);
|
2026-01-18 16:33:54 +00:00
|
|
|
|
|
|
|
|
return $this->popupCallback(true, 'Bluesky account connected!', $this->platform->value);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('Bluesky connection error', [
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
'trace' => $e->getTraceAsString(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return back()->withErrors(['password' => 'Error connecting to Bluesky. Please try again.']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|