coolify/app/Http/Middleware/DecideWhatToDoWithUser.php

53 lines
2.0 KiB
PHP
Raw Normal View History

2023-07-13 22:03:27 +02:00
<?php
namespace App\Http\Middleware;
2023-12-27 16:45:01 +01:00
use App\Providers\RouteServiceProvider;
2023-07-13 22:03:27 +02:00
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
{
if(auth()?->user()?->currentTeam()){
refreshSession(auth()->user()->currentTeam());
}
2023-10-09 14:38:44 +02:00
if (!auth()->user() || !isCloud() || isInstanceAdmin()) {
if (!isCloud() && showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) {
2023-12-27 16:45:01 +01:00
return redirect()->route('boarding');
2023-10-11 14:24:19 +02:00
}
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);
}
return redirect()->route('verify.email');
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-12-28 13:43:03 +01:00
return redirect()->route('subscription.index');
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-12-27 16:45:01 +01:00
return redirect()->route('boarding');
2023-10-09 14:20:55 +02:00
}
if (auth()->user()->hasVerifiedEmail() && $request->path() === 'verify') {
2023-12-27 16:45:01 +01:00
return redirect(RouteServiceProvider::HOME);
2023-10-09 14:20:55 +02:00
}
if (isSubscriptionActive() && $request->path() === 'subscription') {
2023-12-27 16:45:01 +01:00
return redirect(RouteServiceProvider::HOME);
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
}