lasthourcloud/app/Http/Middleware/DecideWhatToDoWithUser.php

62 lines
2.2 KiB
PHP
Raw Normal View History

2023-07-13 20:03:27 +00:00
<?php
namespace App\Http\Middleware;
2023-12-27 15:45:01 +00:00
use App\Providers\RouteServiceProvider;
2023-07-13 20:03:27 +00:00
use Closure;
use Illuminate\Http\Request;
2023-09-15 09:19:36 +00:00
use Illuminate\Support\Str;
2024-06-10 20:43:34 +00:00
use Symfony\Component\HttpFoundation\Response;
2023-07-13 20:03:27 +00:00
2023-10-09 12:20:55 +00:00
class DecideWhatToDoWithUser
2023-07-13 20:03:27 +00:00
{
public function handle(Request $request, Closure $next): Response
{
2024-03-05 08:19:15 +00:00
if (auth()?->user()?->teams?->count() === 0) {
$currentTeam = auth()->user()?->recreate_personal_team();
refreshSession($currentTeam);
}
2024-06-10 20:43:34 +00:00
if (auth()?->user()?->currentTeam()) {
refreshSession(auth()->user()->currentTeam());
}
2024-06-10 20:43:34 +00:00
if (! auth()->user() || ! isCloud() || isInstanceAdmin()) {
if (! isCloud() && showBoarding() && ! in_array($request->path(), allowedPathsForBoardingAccounts())) {
2024-03-13 11:11:37 +00:00
return redirect()->route('onboarding');
2023-10-11 12:24:19 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-24 18:49:54 +00:00
return $next($request);
}
2024-06-10 20:43:34 +00:00
if (! auth()->user()->hasVerifiedEmail()) {
2023-10-09 12:20:55 +00:00
if ($request->path() === 'verify' || in_array($request->path(), allowedPathsForInvalidAccounts()) || $request->routeIs('verify.verify')) {
2023-08-14 13:22:29 +00:00
return $next($request);
}
2024-06-10 20:43:34 +00:00
return redirect()->route('verify.email');
2023-08-14 13:22:29 +00:00
}
2024-06-10 20:43:34 +00:00
if (! isSubscriptionActive() && ! isSubscriptionOnGracePeriod()) {
if (! in_array($request->path(), allowedPathsForUnsubscribedAccounts())) {
2023-09-15 09:19:36 +00:00
if (Str::startsWith($request->path(), 'invitations')) {
return $next($request);
}
2024-06-10 20:43:34 +00:00
2023-12-28 12:43:03 +00:00
return redirect()->route('subscription.index');
2023-10-09 12:20:55 +00:00
}
}
2024-06-10 20:43:34 +00:00
if (showBoarding() && ! in_array($request->path(), allowedPathsForBoardingAccounts())) {
2023-10-09 12:20:55 +00:00
if (Str::startsWith($request->path(), 'invitations')) {
2023-08-14 13:22:29 +00:00
return $next($request);
2023-07-13 20:03:27 +00:00
}
2024-06-10 20:43:34 +00:00
2024-03-13 11:11:37 +00:00
return redirect()->route('onboarding');
2023-10-09 12:20:55 +00:00
}
if (auth()->user()->hasVerifiedEmail() && $request->path() === 'verify') {
2023-12-27 15:45:01 +00:00
return redirect(RouteServiceProvider::HOME);
2023-10-09 12:20:55 +00:00
}
if (isSubscriptionActive() && $request->routeIs('subscription.index')) {
2023-12-27 15:45:01 +00:00
return redirect(RouteServiceProvider::HOME);
2023-07-13 20:03:27 +00:00
}
2024-06-10 20:43:34 +00:00
2023-07-14 10:09:56 +00:00
return $next($request);
2023-07-13 20:03:27 +00:00
}
2023-07-14 09:27:08 +00:00
}