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-08-30 14:01:38 +00:00
|
|
|
class IsSubscriptionValid
|
2023-07-13 20:03:27 +00:00
|
|
|
{
|
|
|
|
public function handle(Request $request, Closure $next): Response
|
|
|
|
{
|
2023-08-24 18:49:54 +00:00
|
|
|
if (isInstanceAdmin()) {
|
|
|
|
return $next($request);
|
|
|
|
}
|
2023-08-31 07:56:37 +00:00
|
|
|
if (!auth()->user() || !isCloud()) {
|
2023-08-14 14:56:13 +00:00
|
|
|
if ($request->path() === 'subscription') {
|
2023-08-14 13:22:29 +00:00
|
|
|
return redirect('/');
|
|
|
|
} else {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|
2023-08-24 14:14:09 +00:00
|
|
|
if (isSubscriptionActive() && $request->path() === 'subscription') {
|
|
|
|
// ray('active subscription Middleware');
|
2023-08-14 13:22:29 +00:00
|
|
|
return redirect('/');
|
|
|
|
}
|
2023-08-24 14:14:09 +00:00
|
|
|
if (isSubscriptionOnGracePeriod()) {
|
|
|
|
// ray('is_subscription_in_grace_period Middleware');
|
2023-08-14 13:22:29 +00:00
|
|
|
return $next($request);
|
|
|
|
}
|
2023-08-24 14:14:09 +00:00
|
|
|
if (!isSubscriptionActive() && !isSubscriptionOnGracePeriod()) {
|
|
|
|
// ray('SubscriptionValid Middleware');
|
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-07-14 09:27:08 +00:00
|
|
|
} else {
|
2023-08-14 13:22:29 +00:00
|
|
|
return $next($request);
|
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
|
|
|
}
|