mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-16 12:33:03 +00:00
feat: cloud
This commit is contained in:
24
app/Http/Controllers/ServerController.php
Normal file
24
app/Http/Controllers/ServerController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PrivateKey;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
|
||||
public function new_server()
|
||||
{
|
||||
$servers = auth()->user()->currentTeam()->servers->count();
|
||||
$subscription = auth()->user()->currentTeam()->subscription->type();
|
||||
$limits = config('constants.limits.server')[strtolower($subscription)];
|
||||
$limit_reached = true ?? $servers >= $limits[$subscription];
|
||||
return view('server.create', [
|
||||
'limit_reached' => $limit_reached,
|
||||
'private_keys' => PrivateKey::ownedByCurrentTeam()->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Livewire\Component;
|
||||
class ByIp extends Component
|
||||
{
|
||||
public $private_keys;
|
||||
public $limit_reached;
|
||||
public int|null $private_key_id = null;
|
||||
public $new_private_key_name;
|
||||
public $new_private_key_description;
|
||||
|
||||
@@ -8,32 +8,38 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SubscriptionValid
|
||||
{
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (auth()->user()) {
|
||||
if (is_cloud() && !isSubscribed()) {
|
||||
ray('SubscriptionValid Middleware');
|
||||
$is_instance_admin = auth()->user()?->isInstanceAdmin();
|
||||
|
||||
$allowed_paths = [
|
||||
'subscription',
|
||||
'login',
|
||||
'register',
|
||||
'logout',
|
||||
'livewire/message/check-license',
|
||||
'livewire/message/switch-team',
|
||||
];
|
||||
if (!in_array($request->path(), $allowed_paths)) {
|
||||
return redirect('subscription');
|
||||
} else {
|
||||
return $next($request);
|
||||
}
|
||||
if (!auth()->user() || !is_cloud()) {
|
||||
if ($request->path() === 'subscription' && !$is_instance_admin) {
|
||||
return redirect('/');
|
||||
} else {
|
||||
if ($request->path() === 'subscription' && !auth()->user()->isInstanceAdmin()) {
|
||||
return redirect('/');
|
||||
} else {
|
||||
return $next($request);
|
||||
}
|
||||
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');
|
||||
|
||||
$allowed_paths = [
|
||||
'subscription',
|
||||
'login',
|
||||
'register',
|
||||
'logout',
|
||||
'livewire/message/check-license',
|
||||
'livewire/message/switch-team',
|
||||
];
|
||||
if (!in_array($request->path(), $allowed_paths)) {
|
||||
return redirect('subscription');
|
||||
} else {
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
return $next($request);
|
||||
|
||||
@@ -12,4 +12,22 @@ class Subscription extends Model
|
||||
{
|
||||
return $this->belongsTo(Team::class);
|
||||
}
|
||||
public function type()
|
||||
{
|
||||
$basic = explode(',', config('coolify.lemon_squeezy_basic_plan_ids'));
|
||||
$pro = explode(',', config('coolify.lemon_squeezy_pro_plan_ids'));
|
||||
$ultimate = explode(',', config('coolify.lemon_squeezy_ultimate_plan_ids'));
|
||||
|
||||
$subscription = $this->lemon_variant_id;
|
||||
if (in_array($subscription, $basic)) {
|
||||
return 'basic';
|
||||
}
|
||||
if (in_array($subscription, $pro)) {
|
||||
return 'pro';
|
||||
}
|
||||
if (in_array($subscription, $ultimate)) {
|
||||
return 'ultimate';
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user