basic license wip

This commit is contained in:
Andras Bacsai 2023-06-22 14:48:47 +02:00
parent fa2f34ba3c
commit d8adea734f
9 changed files with 75 additions and 6 deletions

View File

@ -17,6 +17,10 @@ class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
public function license()
{
return view('license');
}
public function dashboard()
{
$projects = Project::ownedByCurrentTeam()->get();

View File

@ -21,6 +21,7 @@ class Kernel extends HttpKernel
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// \App\Http\Middleware\LicenseValid::class,
];
/**

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Livewire;
use Illuminate\Support\Facades\Cache;
use Livewire\Component;
class License extends Component
{
public string $license;
public function submit()
{
ray('checking license');
$this->validate([
'license' => 'required'
]);
// Pretend we're checking the license
// if ($this->license === '123') {
// ray('license is valid');
// Cache::put('license_key', '123');
// return redirect()->to('/');
// } else {
// ray('license is invalid');
// }
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Symfony\Component\HttpFoundation\Response;
class LicenseValid
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (!config('coolify.self_hosted')) {
$value = Cache::get('license_key');
if (!$value) {
ray($request->path());
if ($request->path() !== 'license' && $request->path() !== 'livewire/message/license') {
return redirect('license');
}
}
}
return $next($request);
}
}

View File

@ -2,21 +2,16 @@
namespace App\Providers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Http::macro('github', function (string $api_url, string|null $github_access_token = null) {

View File

@ -19,9 +19,11 @@
display: none !important;
}
</style>
@livewireStyles
</head>
<body>
@livewireScripts
<main>
{{ $slot }}
</main>

View File

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

View File

@ -0,0 +1,6 @@
<div>
<form wire:submit.prevent='submit'>
<x-forms.input id="license" label="License Key" />
<x-forms.button type='submit'>Check</x-forms.button>
</form>
</div>

View File

@ -86,6 +86,7 @@
Route::middleware(['auth'])->group(function () {
Route::get('/', [Controller::class, 'dashboard'])->name('dashboard');
Route::get('/license', [Controller::class, 'license'])->name('license');
Route::get('/settings', [Controller::class, 'settings'])->name('settings.configuration');
Route::get('/settings/emails', [Controller::class, 'emails'])->name('settings.emails');
Route::get('/profile', fn () => view('profile', ['request' => request()]))->name('profile');