coolify/app/Livewire/Settings/License.php

57 lines
1.4 KiB
PHP
Raw Normal View History

2023-07-14 11:27:08 +02:00
<?php
2024-01-07 16:23:41 +01:00
namespace App\Livewire\Settings;
2023-07-14 11:27:08 +02:00
use App\Actions\License\CheckResaleLicense;
use App\Models\InstanceSettings;
use Livewire\Component;
2024-01-07 16:23:41 +01:00
class License extends Component
2023-07-14 11:27:08 +02:00
{
2024-01-07 16:23:41 +01:00
public InstanceSettings $settings;
2024-06-10 22:43:34 +02:00
public ?string $instance_id = null;
2024-01-07 16:23:41 +01:00
2023-07-14 11:27:08 +02:00
protected $rules = [
'settings.resale_license' => 'nullable',
'settings.is_resale_license_active' => 'nullable',
];
2024-06-10 22:43:34 +02:00
2023-07-14 11:27:08 +02:00
protected $validationAttributes = [
'settings.resale_license' => 'License',
'instance_id' => 'Instance Id (Do not change this)',
'settings.is_resale_license_active' => 'Is License Active',
];
2024-06-10 22:43:34 +02:00
public function mount()
{
if (! isCloud()) {
2024-01-07 16:23:41 +01:00
abort(404);
}
2023-07-14 11:27:08 +02:00
$this->instance_id = config('app.id');
2024-07-12 15:45:36 +02:00
$this->settings = \App\Models\InstanceSettings::get();
2023-07-14 11:27:08 +02:00
}
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public function render()
{
2024-03-22 11:34:15 +01:00
return view('livewire.settings.license');
2024-01-07 16:23:41 +01:00
}
2024-06-10 22:43:34 +02:00
2023-07-14 11:27:08 +02:00
public function submit()
{
$this->validate();
$this->settings->save();
if ($this->settings->resale_license) {
try {
CheckResaleLicense::run();
2023-12-07 19:06:32 +01:00
$this->dispatch('reloadWindow');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
2024-06-10 22:43:34 +02:00
session()->flash('error', 'Something went wrong. Please contact support. <br>Error: '.$e->getMessage());
2023-09-11 17:36:30 +02:00
ray($e->getMessage());
2024-06-10 22:43:34 +02:00
2023-12-27 16:45:01 +01:00
return redirect()->route('settings.license');
2023-07-14 11:27:08 +02:00
}
}
}
}