transition
This commit is contained in:
@@ -13,11 +13,13 @@ use Lucent\Account\AuthService;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use Lucent\Util\Form\FormException;
|
||||
use Lucent\Util\Form\ResponseFormError;
|
||||
use function Lucent\Response\fail;
|
||||
use function Lucent\Response\ok;
|
||||
|
||||
|
||||
class AuthController extends Controller
|
||||
class AuthController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AuthService $authService,
|
||||
@@ -65,52 +67,39 @@ class AuthController extends Controller
|
||||
return ok();
|
||||
}
|
||||
|
||||
public function login(): View|RedirectResponse
|
||||
public function login()
|
||||
{
|
||||
|
||||
if ($this->accountService->countUsers() == 0) {
|
||||
return redirect($this->channelService->channel->lucentUrl . "/register");
|
||||
}
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "login",
|
||||
title: "Log in"
|
||||
);
|
||||
return view("lucent::auth.login");
|
||||
}
|
||||
|
||||
public function postLogin(Request $request): Response
|
||||
public function postLogin(Request $request)
|
||||
{
|
||||
try {
|
||||
$this->authService->sendLoginEmail($request->input("email"));
|
||||
} catch (LucentException $th) {
|
||||
return fail($th);
|
||||
}
|
||||
$this->authService->sendLoginEmail($request->input("email"));
|
||||
|
||||
return ok();
|
||||
return view("lucent::auth.login-success");
|
||||
}
|
||||
|
||||
public function verify(Request $request): View
|
||||
{
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "verify",
|
||||
title: "Verify and enter",
|
||||
data: [
|
||||
"email" => $request->input("email"),
|
||||
"token" => $request->input("token"),
|
||||
]
|
||||
);
|
||||
return view("lucent::auth.verify", [
|
||||
"email" => $request->input("email"),
|
||||
"token" => $request->input("token"),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function postVerify(Request $request): Response
|
||||
public function postVerify(Request $request)
|
||||
{
|
||||
try {
|
||||
$this->authService->login($request->input("email"), $request->input("token"));
|
||||
} catch (LucentException $th) {
|
||||
return fail($th);
|
||||
return ResponseFormError::fromException($th);
|
||||
}
|
||||
return ok();
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,14 +21,36 @@ class HomeController extends Controller
|
||||
{
|
||||
}
|
||||
|
||||
public function home(): View
|
||||
public function home(Request $request): View
|
||||
{
|
||||
$urlParams = $request->all();
|
||||
$users = $this->accountService->all();
|
||||
|
||||
$sort = data_get($urlParams, "sort") ?? "-_sys.updatedAt";
|
||||
$filter = data_get($urlParams, "filter") ?? [];
|
||||
$arguments = array_merge([
|
||||
"schema_in" => $this->accountService->currentReadableSchemas(),
|
||||
"status_in" => ["draft", "published"]
|
||||
], $filter);
|
||||
|
||||
$limit = 10;
|
||||
|
||||
$graph = $this->query
|
||||
->filter($arguments)
|
||||
->limit($limit)
|
||||
->childrenDepth(1)
|
||||
->parentsDepth(0)
|
||||
->sort($sort)
|
||||
->run();
|
||||
|
||||
|
||||
return view("lucent::home", [
|
||||
"users" => $users,
|
||||
"records" => $graph->getRootRecords(),
|
||||
"graph" => toArray($graph),
|
||||
"modalUrl" => $request->fullUrl(),
|
||||
]);
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "channel",
|
||||
view: "homeIndex",
|
||||
title: "Records",
|
||||
);
|
||||
}
|
||||
|
||||
public function records(Request $request): Response
|
||||
|
||||
@@ -4,15 +4,19 @@ namespace Lucent\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Lucent\Account\AccountService;
|
||||
use Lucent\Account\AuthService;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\ViewModel\ViewModel;
|
||||
|
||||
readonly class AuthMiddleware
|
||||
{
|
||||
public function __construct(
|
||||
private AuthService $authService,
|
||||
private ChannelService $channelService
|
||||
private AccountService $accountService,
|
||||
private ChannelService $channelService,
|
||||
private ViewModel $viewModel
|
||||
)
|
||||
{
|
||||
}
|
||||
@@ -22,9 +26,11 @@ readonly class AuthMiddleware
|
||||
if (!$this->authService->isLoggedIn()) {
|
||||
return redirect($this->channelService->channel->lucentUrl . "/login");
|
||||
}
|
||||
|
||||
$this->authService->refreshSession();
|
||||
|
||||
View::share("channel",$this->channelService->channel);
|
||||
View::share("user",session("user"));
|
||||
View::share("schemas",$this->channelService->channel->schemas->whereIn("name",$this->accountService->currentReadableSchemas())->values());
|
||||
View::share("viewModel",$this->viewModel);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user