lots
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
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\Account\AuthService;
|
||||
use Lucent\Account\UserRepo;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use function Lucent\Response\fail;
|
||||
@@ -18,29 +20,28 @@ use function Lucent\Response\ok;
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AuthService $authService,
|
||||
private readonly Svelte $svelte,
|
||||
private readonly UserRepo $userRepo,
|
||||
private readonly AuthService $authService,
|
||||
private readonly AccountService $accountService,
|
||||
private readonly ChannelService $channelService,
|
||||
private readonly Session $session,
|
||||
private readonly Svelte $svelte,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function register(Request $request): View
|
||||
public function register(Request $request): View|RedirectResponse
|
||||
{
|
||||
$userCount = $this->userRepo->count();
|
||||
$email = $request->input("email");
|
||||
$token = $request->input("token");
|
||||
if ($this->accountService->countUsers() > 0) {
|
||||
return redirect($this->channelService->channel->lucentUrl . "/login");
|
||||
}
|
||||
|
||||
return svelte(
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "register",
|
||||
title: "Create an account",
|
||||
data: [
|
||||
'email' => $email,
|
||||
'token' => $token,
|
||||
'userCount' => $userCount
|
||||
]
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,23 +49,15 @@ class AuthController extends Controller
|
||||
public function postRegister(Request $request): Response
|
||||
{
|
||||
|
||||
if ($this->accountService->countUsers() > 0) {
|
||||
abort(400);
|
||||
}
|
||||
|
||||
try {
|
||||
if ($request->input("isAdmin")) {
|
||||
$this->authService->registerAdmin(
|
||||
name: $request->input("name"),
|
||||
password: $request->input("password"),
|
||||
email: $request->input("email"),
|
||||
);
|
||||
} else {
|
||||
$this->authService->register(
|
||||
name: $request->input("name"),
|
||||
password: $request->input("password"),
|
||||
email: $request->input("email"),
|
||||
token: $request->input("token") ?? "",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$this->authService->registerAdmin(
|
||||
name: $request->input("name"),
|
||||
email: $request->input("email"),
|
||||
);
|
||||
} catch (LucentException $th) {
|
||||
return fail($th);
|
||||
}
|
||||
@@ -72,8 +65,12 @@ class AuthController extends Controller
|
||||
return ok();
|
||||
}
|
||||
|
||||
public function login(): View
|
||||
public function login(): View|RedirectResponse
|
||||
{
|
||||
if ($this->accountService->countUsers() == 0) {
|
||||
return redirect($this->channelService->channel->lucentUrl . "/register");
|
||||
}
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "login",
|
||||
@@ -118,8 +115,8 @@ class AuthController extends Controller
|
||||
|
||||
public function logout(): RedirectResponse
|
||||
{
|
||||
session()->flush();
|
||||
return redirect("/login");
|
||||
$this->session->flush();
|
||||
return redirect($this->channelService->channel->lucentUrl . "/login");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user