2023-07-13 22:03:27 +02: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 15:22:29 +02:00
|
|
|
if (!auth()->user() || !is_cloud()) {
|
2023-08-14 16:56:13 +02:00
|
|
|
if ($request->path() === 'subscription') {
|
2023-08-14 15:22:29 +02:00
|
|
|
return redirect('/');
|
|
|
|
} else {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|
2023-08-22 17:44:49 +02:00
|
|
|
if (isInstanceAdmin()) {
|
2023-08-14 16:56:13 +02:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_subscription_active() && $request->path() === 'subscription') {
|
2023-08-14 15:22:29 +02:00
|
|
|
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 12:09:56 +02:00
|
|
|
|
2023-08-14 15:22:29 +02:00
|
|
|
$allowed_paths = [
|
|
|
|
'subscription',
|
|
|
|
'login',
|
|
|
|
'register',
|
2023-08-15 14:11:38 +02:00
|
|
|
'waitlist',
|
|
|
|
'force-password-reset',
|
2023-08-14 15:22:29 +02:00
|
|
|
'logout',
|
2023-08-15 14:11:38 +02:00
|
|
|
'livewire/message/force-password-reset',
|
2023-08-14 15:22:29 +02:00
|
|
|
'livewire/message/check-license',
|
|
|
|
'livewire/message/switch-team',
|
|
|
|
];
|
|
|
|
if (!in_array($request->path(), $allowed_paths)) {
|
|
|
|
return redirect('subscription');
|
2023-07-14 11:27:08 +02:00
|
|
|
} else {
|
2023-08-14 15:22:29 +02:00
|
|
|
return $next($request);
|
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
|
|
|
}
|