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