79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Lucent\Http\Controller;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use Illuminate\Contracts\Session\Session;
|
||
|
|
use Illuminate\Contracts\View\View;
|
||
|
|
use Illuminate\Http\RedirectResponse;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Http\Response;
|
||
|
|
use Lucent\Account\AccountService;
|
||
|
|
use Lucent\Channel\ChannelService;
|
||
|
|
use Lucent\LucentException;
|
||
|
|
use Lucent\Setup\Data\SetupStep;
|
||
|
|
use Lucent\Setup\Setup;
|
||
|
|
use Lucent\Setup\Step\ComposerStep;
|
||
|
|
use Lucent\Setup\Step\IStep;
|
||
|
|
use Lucent\Setup\Step\LucentConfigStep;
|
||
|
|
use Lucent\Svelte\Svelte;
|
||
|
|
use function Lucent\Response\fail;
|
||
|
|
use function Lucent\Response\ok;
|
||
|
|
|
||
|
|
|
||
|
|
class SetupController
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private readonly AccountService $accountService,
|
||
|
|
private readonly ChannelService $channelService,
|
||
|
|
private readonly Svelte $svelte,
|
||
|
|
private readonly Setup $setup,
|
||
|
|
)
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setup(Request $request): View|RedirectResponse
|
||
|
|
{
|
||
|
|
if ($this->accountService->countUsers() > 0) {
|
||
|
|
return redirect($this->channelService->channel->lucentUrl . "/login");
|
||
|
|
}
|
||
|
|
|
||
|
|
$steps = array_reduce([
|
||
|
|
new ComposerStep,
|
||
|
|
new LucentConfigStep,
|
||
|
|
],fn(array $carry, IStep $setupStep)=> array_merge($carry,[$setupStep()]) ,[]);
|
||
|
|
|
||
|
|
return $this->svelte->render(
|
||
|
|
layout: "account",
|
||
|
|
view: "setup",
|
||
|
|
title: "Setup Lucent",
|
||
|
|
data: [
|
||
|
|
"steps" => $steps
|
||
|
|
]
|
||
|
|
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public function postRegister(Request $request): Response
|
||
|
|
{
|
||
|
|
|
||
|
|
if ($this->accountService->countUsers() > 0) {
|
||
|
|
abort(400);
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
$this->authService->registerAdmin(
|
||
|
|
name: $request->input("name"),
|
||
|
|
email: $request->input("email"),
|
||
|
|
);
|
||
|
|
} catch (LucentException $th) {
|
||
|
|
return fail($th);
|
||
|
|
}
|
||
|
|
|
||
|
|
return ok();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|