die tenant admin oauth authentifizierung wurde implementiert und funktioniert jetzt. Zudem wurde das marketing frontend dashboard implementiert.
This commit is contained in:
@@ -2,45 +2,73 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Response;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$user = Auth::user()->load('purchases.packages');
|
||||
$user = $request->user()
|
||||
->load(['tenant' => function ($query) {
|
||||
$query->with([
|
||||
'purchases' => fn ($purchases) => $purchases
|
||||
->with('package')
|
||||
->latest('purchased_at')
|
||||
->limit(10),
|
||||
'tenantPackages' => fn ($packages) => $packages
|
||||
->with('package')
|
||||
->orderByDesc('active')
|
||||
->orderByDesc('purchased_at'),
|
||||
]);
|
||||
}]);
|
||||
|
||||
$tenant = $user->tenant;
|
||||
$activePackage = $tenant?->tenantPackages
|
||||
?->first(fn ($package) => (bool) $package->active);
|
||||
|
||||
$purchases = $tenant?->purchases
|
||||
?->map(fn ($purchase) => [
|
||||
'id' => $purchase->id,
|
||||
'packageName' => $purchase->package?->getNameForLocale(app()->getLocale())
|
||||
?? $purchase->package?->name
|
||||
?? __('Unknown package'),
|
||||
'price' => $purchase->price !== null ? (float) $purchase->price : null,
|
||||
'purchasedAt' => optional($purchase->purchased_at)->toIso8601String(),
|
||||
'type' => $purchase->type,
|
||||
'provider' => $purchase->provider,
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return Inertia::render('Profile/Index', [
|
||||
'user' => $user,
|
||||
'userData' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'username' => $user->username,
|
||||
'preferredLocale' => $user->preferred_locale,
|
||||
'emailVerifiedAt' => optional($user->email_verified_at)->toIso8601String(),
|
||||
'mustVerifyEmail' => $user instanceof MustVerifyEmail,
|
||||
],
|
||||
'tenant' => $tenant ? [
|
||||
'id' => $tenant->id,
|
||||
'name' => $tenant->name,
|
||||
'eventCreditsBalance' => $tenant->event_credits_balance,
|
||||
'subscriptionStatus' => $tenant->subscription_status,
|
||||
'subscriptionExpiresAt' => optional($tenant->subscription_expires_at)->toIso8601String(),
|
||||
'activePackage' => $activePackage ? [
|
||||
'name' => $activePackage->package?->getNameForLocale(app()->getLocale())
|
||||
?? $activePackage->package?->name
|
||||
?? __('Unknown package'),
|
||||
'price' => $activePackage->price !== null ? (float) $activePackage->price : null,
|
||||
'expiresAt' => optional($activePackage->expires_at)->toIso8601String(),
|
||||
'remainingEvents' => $activePackage->remaining_events ?? null,
|
||||
] : null,
|
||||
] : null,
|
||||
'purchases' => $purchases,
|
||||
]);
|
||||
}
|
||||
|
||||
public function account()
|
||||
{
|
||||
$user = Auth::user()->load('purchases.packages');
|
||||
if (request()->isMethod('post')) {
|
||||
$validated = request()->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|unique:users,email,' . $user->id,
|
||||
]);
|
||||
|
||||
$user->update($validated);
|
||||
|
||||
return back()->with('success', 'Profil aktualisiert.');
|
||||
}
|
||||
|
||||
return Inertia::render('Profile/Account', [
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$user = Auth::user()->load('purchases.packages');
|
||||
return Inertia::render('Profile/Orders', [
|
||||
'purchases' => $user->purchases,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user