setup complete

This commit is contained in:
2024-09-06 23:30:12 +03:00
parent a73ee21568
commit 6fc0a65b6f
22 changed files with 351 additions and 330 deletions
+22 -28
View File
@@ -3,7 +3,6 @@
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;
@@ -12,10 +11,15 @@ use Lucent\Account\AccountService;
use Lucent\Channel\ChannelService;
use Lucent\LucentException;
use Lucent\Setup\Data\SetupStep;
use Lucent\Setup\Data\SetupStepStatus;
use Lucent\Setup\Setup;
use Lucent\Setup\Step\ComposerStep;
use Lucent\Setup\Step\DatabaseSetupStep;
use Lucent\Setup\Step\IStep;
use Lucent\Setup\Step\LaravelEnvStep;
use Lucent\Setup\Step\LucentConfigStep;
use Lucent\Setup\Step\StorageLinkSetupStep;
use Lucent\Setup\Step\StorageSetupStep;
use Lucent\Svelte\Svelte;
use function Lucent\Response\fail;
use function Lucent\Response\ok;
@@ -27,7 +31,6 @@ class SetupController
private readonly AccountService $accountService,
private readonly ChannelService $channelService,
private readonly Svelte $svelte,
private readonly Setup $setup,
)
{
@@ -35,44 +38,35 @@ class SetupController
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()]) ,[]);
new ComposerStep,
new LucentConfigStep,
new LaravelEnvStep,
new StorageSetupStep,
new StorageLinkSetupStep,
new DatabaseSetupStep,
], fn(array $carry, IStep $setupStep) => array_merge($carry, [$setupStep()]), []);
$allSuccess = array_reduce($steps, fn(bool $carry, SetupStep $step) => !$carry ? false : $step->status === SetupStepStatus::SUCCESS, true);
if($allSuccess){
if ($this->accountService->countUsers() > 0) {
return redirect($this->channelService->channel->lucentUrl . "/login");
}
}
return $this->svelte->render(
layout: "account",
view: "setup",
title: "Setup Lucent",
data: [
"steps" => $steps
"steps" => $steps,
"allSuccess" => $allSuccess,
]
);
}
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();
}
}
+5 -1
View File
@@ -13,14 +13,18 @@ use Lucent\Http\Controller\RevisionController;
use Lucent\Http\Controller\SetupController;
Route::get('/lucent/setup', [SetupController::class, 'setup']);
Route::group([
'middleware' => ['web'],
'prefix' => "lucent"
], function () {
Route::middleware(['lucent.guest'])->group(function () {
Route::get('/', [AuthController::class, 'login']);
Route::get('/setup', [SetupController::class, 'setup']);
Route::get('/register', [AuthController::class, 'register']);
Route::post('/register', [AuthController::class, 'postRegister']);
Route::get('/login', [AuthController::class, 'login']);