coolify/app/Http/Middleware/DecideWhatToDoWithUser.php

49 lines
1.7 KiB
PHP
Raw Normal View History

2023-07-13 22:03:27 +02:00
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
2023-09-15 11:19:36 +02:00
use Illuminate\Support\Str;
2023-07-13 22:03:27 +02:00
2023-10-09 14:20:55 +02:00
class DecideWhatToDoWithUser
2023-07-13 22:03:27 +02:00
{
public function handle(Request $request, Closure $next): Response
{
2023-10-09 14:38:44 +02:00
if (!auth()->user() || !isCloud() || isInstanceAdmin()) {
if (!isCloud() && showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) {
2023-10-11 14:24:19 +02:00
return redirect('boarding');
}
2023-08-24 20:49:54 +02:00
return $next($request);
}
2023-10-09 14:20:55 +02:00
if (!auth()->user()->hasVerifiedEmail()) {
if ($request->path() === 'verify' || in_array($request->path(), allowedPathsForInvalidAccounts()) || $request->routeIs('verify.verify')) {
2023-08-14 15:22:29 +02:00
return $next($request);
}
2023-10-09 14:20:55 +02:00
return redirect('/verify');
2023-08-14 15:22:29 +02:00
}
2023-08-24 16:14:09 +02:00
if (!isSubscriptionActive() && !isSubscriptionOnGracePeriod()) {
2023-08-24 17:41:11 +02:00
if (!in_array($request->path(), allowedPathsForUnsubscribedAccounts())) {
2023-09-15 11:19:36 +02:00
if (Str::startsWith($request->path(), 'invitations')) {
return $next($request);
}
2023-08-14 15:22:29 +02:00
return redirect('subscription');
2023-10-09 14:20:55 +02:00
}
}
if (showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) {
if (Str::startsWith($request->path(), 'invitations')) {
2023-08-14 15:22:29 +02:00
return $next($request);
2023-07-13 22:03:27 +02:00
}
2023-10-09 14:20:55 +02:00
return redirect('boarding');
}
if (auth()->user()->hasVerifiedEmail() && $request->path() === 'verify') {
return redirect('/');
}
if (isSubscriptionActive() && $request->path() === 'subscription') {
return redirect('/');
2023-07-13 22:03:27 +02:00
}
2023-07-14 12:09:56 +02:00
return $next($request);
2023-07-13 22:03:27 +02:00
}
2023-07-14 11:27:08 +02:00
}