diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 98faaad2e..c9620f4bd 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -19,10 +19,22 @@ class Controller extends BaseController public function subscription() { + if (!isCloud()) { + abort(404); + } return view('subscription', [ 'settings' => InstanceSettings::get() ]); } + public function license() + { + if (!isCloud()) { + abort(404); + } + return view('settings.license', [ + 'settings' => InstanceSettings::get() + ]); + } public function dashboard() { $projects = Project::ownedByCurrentTeam()->get(); diff --git a/app/Http/Livewire/CheckLicense.php b/app/Http/Livewire/CheckLicense.php index 59942c6a6..38ee0e636 100644 --- a/app/Http/Livewire/CheckLicense.php +++ b/app/Http/Livewire/CheckLicense.php @@ -35,7 +35,7 @@ public function submit() } catch (\Throwable $th) { session()->flash('error', 'License is not valid. Please contact support.'); ray($th->getMessage()); - return redirect()->to('/subscription'); + return redirect()->to('/settings/license'); } } } diff --git a/app/Http/Middleware/SubscriptionValid.php b/app/Http/Middleware/SubscriptionValid.php index ab2d9eb1f..e7fcdff3c 100644 --- a/app/Http/Middleware/SubscriptionValid.php +++ b/app/Http/Middleware/SubscriptionValid.php @@ -11,27 +11,31 @@ class SubscriptionValid public function handle(Request $request, Closure $next): Response { - $allowed_paths = [ - 'subscription', - 'login', - 'register', - 'logout', - 'livewire/message/check-license', - 'livewire/message/switch-team', - ]; - if (isCloud() && !isSubscribed()) { - ray('SubscriptionValid Middleware'); - if (!in_array($request->path(), $allowed_paths)) { - return redirect('subscription'); + if (auth()->user()) { + if (isCloud() && !isSubscribed()) { + 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); + } } else { - return $next($request); - } - } else { - if ($request->path() === 'subscription') { - return redirect('/'); - } else { - return $next($request); + if ($request->path() === 'subscription' && !auth()->user()->isInstanceAdmin()) { + return redirect('/'); + } else { + return $next($request); + } } } + return $next($request); } } diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php index 5f0cc8c00..b5c01f1fb 100644 --- a/app/Models/InstanceSettings.php +++ b/app/Models/InstanceSettings.php @@ -18,6 +18,7 @@ class InstanceSettings extends Model implements SendsEmail ]; protected $casts = [ 'smtp' => SchemalessAttributes::class, + 'resale_license' => 'encrypted', ]; public function scopeWithSmtp(): Builder { diff --git a/app/View/Components/Forms/Input.php b/app/View/Components/Forms/Input.php index c1dc45819..b22bc11dc 100644 --- a/app/View/Components/Forms/Input.php +++ b/app/View/Components/Forms/Input.php @@ -16,13 +16,12 @@ public function __construct( public string|null $type = 'text', public string|null $value = null, public string|null $label = null, - public string|null $placeholder = null, public bool $required = false, public bool $disabled = false, public bool $readonly = false, public string|null $helper = null, public bool $allowToPeak = true, - public string $defaultClass = "input input-sm bg-coolgray-200 rounded text-white w-full disabled:bg-coolgray-200/50 disabled:border-none" + public string $defaultClass = "input input-sm bg-coolgray-200 rounded text-white w-full disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500" ) { } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index f45825686..71a2f3560 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -130,5 +130,5 @@ function isDev() } function isCloud() { - return (bool)config('coolify.self_hosted') === false; + return !config('coolify.self_hosted'); } diff --git a/bootstrap/helpers/subscriptions.php b/bootstrap/helpers/subscriptions.php index 319212fd4..7e291fabc 100644 --- a/bootstrap/helpers/subscriptions.php +++ b/bootstrap/helpers/subscriptions.php @@ -33,11 +33,13 @@ function getRenewDate() } function getEndDate() { - return Carbon::parse(auth()->user()->currentTeam()->subscription->lemon_ends_at)->format('Y-M-d H:i:s'); + return Carbon::parse(auth()->user()->currentTeam()->subscription->lemon_renews_at)->format('Y-M-d H:i:s'); } function isSubscribed() { return auth()->user()?->currentTeam()?->subscription?->lemon_status === 'active' || - (auth()->user()?->currentTeam()?->subscription?->lemon_ends_at && Carbon::parse(auth()->user()->currentTeam()->subscription->lemon_ends_at) > Carbon::now()); + (auth()->user()?->currentTeam()?->subscription?->lemon_ends_at && + Carbon::parse(auth()->user()->currentTeam()->subscription->lemon_ends_at) > Carbon::now() + ) || auth()->user()->isInstanceAdmin(); } diff --git a/database/migrations/2023_07_13_120721_add_license_to_instance_settings.php b/database/migrations/2023_07_13_120721_add_license_to_instance_settings.php index 69598ece1..c32cd0f9a 100644 --- a/database/migrations/2023_07_13_120721_add_license_to_instance_settings.php +++ b/database/migrations/2023_07_13_120721_add_license_to_instance_settings.php @@ -13,7 +13,7 @@ public function up(): void { Schema::table('instance_settings', function (Blueprint $table) { $table->boolean('is_resale_license_active')->default(false); - $table->string('resale_license')->nullable(); + $table->longText('resale_license')->nullable(); }); } diff --git a/resources/views/components/layout-subscription.blade.php b/resources/views/components/layout-subscription.blade.php index c87f0b104..3feb21628 100644 --- a/resources/views/components/layout-subscription.blade.php +++ b/resources/views/components/layout-subscription.blade.php @@ -25,12 +25,37 @@
@livewireScripts