trypost/app/Http/Controllers/App/Settings/AccountController.php
Paulo Castellano a8bb44f0e5 fix: self-host billing bypass, Facebook API metrics migration, X token refresh, and duplicate social accounts
- Block all billing/usage/subscribe routes in self-hosted mode (redirect to calendar)
- Hide billing_email field in account settings when self-hosted
- Migrate deprecated Facebook Page Insights metrics to new Media Views API (v25.0)
- Fix X analytics token refresh to use Basic Auth (matching XPublisher/ConnectionVerifier)
- Prevent duplicate social accounts by using updateOrCreate across all OAuth controllers
2026-04-15 09:46:18 -03:00

65 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\App\Settings;
use App\Http\Controllers\App\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class AccountController extends Controller
{
public function edit(Request $request): Response
{
abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);
$account = $request->user()->account;
return Inertia::render('settings/Account', [
'account' => [
'id' => $account->id,
'name' => $account->name,
'billing_email' => $account->billing_email,
],
'selfHosted' => config('trypost.self_hosted'),
]);
}
public function update(Request $request): RedirectResponse
{
abort_unless($request->user()->isAccountOwner(), SymfonyResponse::HTTP_FORBIDDEN);
$isSelfHosted = config('trypost.self_hosted');
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'billing_email' => [$isSelfHosted ? 'nullable' : 'required', 'email', 'max:255'],
]);
$account = $request->user()->account;
$data = ['name' => data_get($validated, 'name')];
if (! $isSelfHosted) {
$data['billing_email'] = data_get($validated, 'billing_email');
}
$account->update($data);
if (! $isSelfHosted && $account->hasStripeId()) {
$account->updateStripeCustomer([
'name' => data_get($validated, 'name'),
'email' => data_get($validated, 'billing_email'),
]);
}
session()->flash('flash.banner', __('settings.flash.account_updated'));
session()->flash('flash.bannerStyle', 'success');
return back();
}
}