2023-07-13 20:03:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
class SubscriptionValid
|
|
|
|
{
|
|
|
|
public function handle(Request $request, Closure $next): Response
|
|
|
|
{
|
2023-08-14 13:22:29 +00:00
|
|
|
$is_instance_admin = auth()->user()?->isInstanceAdmin();
|
|
|
|
|
|
|
|
if (!auth()->user() || !is_cloud()) {
|
|
|
|
if ($request->path() === 'subscription' && !$is_instance_admin) {
|
|
|
|
return redirect('/');
|
|
|
|
} else {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_subscription_active() && $request->path() === 'subscription' && !$is_instance_admin) {
|
|
|
|
return redirect('/');
|
|
|
|
}
|
|
|
|
if (is_subscription_in_grace_period()) {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
if (!is_subscription_active() && !is_subscription_in_grace_period()) {
|
|
|
|
ray('SubscriptionValid Middleware');
|
2023-07-14 10:09:56 +00:00
|
|
|
|
2023-08-14 13:22:29 +00:00
|
|
|
$allowed_paths = [
|
|
|
|
'subscription',
|
|
|
|
'login',
|
|
|
|
'register',
|
|
|
|
'logout',
|
|
|
|
'livewire/message/check-license',
|
|
|
|
'livewire/message/switch-team',
|
|
|
|
];
|
|
|
|
if (!in_array($request->path(), $allowed_paths)) {
|
|
|
|
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
|
|
|
}
|