This commit is contained in:
Andras Bacsai 2023-07-14 12:09:56 +02:00
parent a96fb46296
commit 9f4342bd19
16 changed files with 100 additions and 49 deletions

View File

@ -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();

View File

@ -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');
}
}
}

View File

@ -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);
}
}

View File

@ -18,6 +18,7 @@ class InstanceSettings extends Model implements SendsEmail
];
protected $casts = [
'smtp' => SchemalessAttributes::class,
'resale_license' => 'encrypted',
];
public function scopeWithSmtp(): Builder
{

View File

@ -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"
) {
}

View File

@ -130,5 +130,5 @@ function isDev()
}
function isCloud()
{
return (bool)config('coolify.self_hosted') === false;
return !config('coolify.self_hosted');
}

View File

@ -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();
}

View File

@ -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();
});
}

View File

@ -25,12 +25,37 @@
<body>
@livewireScripts
<x-toaster-hub />
<x-navbar-subscription />
@if (auth()->user()->isInstanceAdmin())
<div class="fixed top-3 left-4" id="vue">
<magic-bar></magic-bar>
</div>
<x-navbar />
@else
<x-navbar-subscription />
@endif
<main class="main">
{{ $slot }}
</main>
<x-version class="fixed left-2 bottom-1" />
<script>
function changePasswordFieldType(event) {
let element = event.target
for (let i = 0; i < 10; i++) {
if (element.className === "relative") {
break;
}
element = element.parentElement;
}
element = element.children[1];
if (element.nodeName === 'INPUT') {
if (element.type === 'password') {
element.type = 'text';
} else {
element.type = 'password';
}
}
}
Livewire.on('reloadWindow', () => {
window.location.reload();
})

View File

@ -93,11 +93,11 @@ class="{{ request()->is('settings*') ? 'text-warning icon' : 'icon' }}" viewBox=
</a>
</li>
@endif
<div class="flex-1"></div>
<li class="pb-6" title="Logout">
<form action="/logout" method="POST" class=" hover:bg-transparent">
@csrf
<button class="rounded-none hover:text-white hover:bg-transparent"> <svg
<button type="submit" class="rounded-none hover:text-white hover:bg-transparent"> <svg
xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />

View File

@ -9,6 +9,12 @@
<a class="{{ request()->routeIs('settings.emails') ? 'text-white' : '' }}" href="{{ route('settings.emails') }}">
<button>SMTP</button>
</a>
@if (isCloud())
<a class="{{ request()->routeIs('settings.license') ? 'text-white' : '' }}"
href="{{ route('settings.license') }}">
<button>Resale License</button>
</a>
@endif
<div class="flex-1"></div>
</nav>
</div>

View File

@ -1,4 +0,0 @@
<x-layout-simple>
<h1>Lincese Key</h1>
<livewire:license />
</x-layout-simple>

View File

@ -1,14 +1,21 @@
<form wire:submit.prevent='submit' class="flex flex-col gap-2">
<div class="w-32">
<x-forms.checkbox id="settings.is_resale_license_active" label="Is license active?" disabled />
<div>
@if ($settings->is_resale_license_active)
<div class="text-success">License is active</div>
@else
<div class="text-error">License is not active</div>
@endif
</div>
<div class="flex gap-2">
<x-forms.input id="settings.resale_license" label="License" />
<x-forms.input id="instance_id" label="Instance Id (do not change this)" disabled />
<x-forms.input type="password" id="settings.resale_license" placeholder="eg: BE558E91-0CC5-4AA2-B1C0-B6403C2988DD"
label="License Key" />
<x-forms.input type="password" id="instance_id" label="Instance Id (do not change this)" disabled />
</div>
<div class="flex gap-2">
<x-forms.button type="submit">
Check License
</x-forms.button>
</div>
<x-forms.button type="submit">
Check License
</x-forms.button>
@if (session()->has('error'))
<div class="text-error">
{{ session('error') }}

View File

@ -0,0 +1,5 @@
<x-layout-subscription>
<x-settings.navbar />
<h3>Resale License</h3>
<livewire:check-license />
</x-layout-subscription>

View File

@ -1,13 +1,4 @@
<x-layout-subscription>
@if (auth()->user()->isInstanceAdmin())
<div class="pb-10">
<h3>Resale License</h3>
<livewire:check-license />
</div>
@endif
@if (!auth()->user()->isInstanceAdmin() && !$settings->is_resale_license_active)
<div>Resale license is not active. Please contact your instance admin.</div>
@endif
@if ($settings->is_resale_license_active)
<div class="flex gap-2">
<h3>Subscription</h3>
@ -37,5 +28,7 @@
<x-forms.button><a class="text-white" href="https://app.lemonsqueezy.com/my-orders">Manage My
Subscription</a>
</x-forms.button>
@else
<div>Resale license is not active. Please contact your instance admin.</div>
@endif
</x-layout-subscription>

View File

@ -87,6 +87,7 @@
Route::get('/subscription', [Controller::class, 'subscription'])->name('subscription');
Route::get('/settings', [Controller::class, 'settings'])->name('settings.configuration');
Route::get('/settings/emails', [Controller::class, 'emails'])->name('settings.emails');
Route::get('/settings/license', [Controller::class, 'license'])->name('settings.license');
Route::get('/profile', fn () => view('profile', ['request' => request()]))->name('profile');
Route::get('/team', [Controller::class, 'team'])->name('team.show');
Route::get('/team/new', fn () => view('team.create'))->name('team.create');