diff --git a/src/app/Http/Controllers/LoginController.php b/src/app/Http/Controllers/LoginController.php new file mode 100644 index 0000000..aadb9fb --- /dev/null +++ b/src/app/Http/Controllers/LoginController.php @@ -0,0 +1,37 @@ +userRepository->findByUsername(new Username($request->username())); + + $payload = AdminInitiateAuthPayload::createForAdminUserPasswordAuthFlow($user->username(), $request->password()); + $this->adminInitiateAuth->execute($payload); + + Auth::loginUsingId($user->userId()); + Session::regenerate(); + Session::regenerateToken(); + + return redirect()->route('dashboard'); + } +} diff --git a/src/app/Http/Requests/LoginRequest.php b/src/app/Http/Requests/LoginRequest.php new file mode 100644 index 0000000..35bc6a6 --- /dev/null +++ b/src/app/Http/Requests/LoginRequest.php @@ -0,0 +1,28 @@ + ['required', 'string'], + 'password' => ['required', 'string'], + ]; + } + + public function username(): string + { + return $this->input('username'); + } + + public function password(): string + { + return $this->input('password'); + } +} diff --git a/src/resources/views/login.blade.php b/src/resources/views/login.blade.php new file mode 100644 index 0000000..2e8b784 --- /dev/null +++ b/src/resources/views/login.blade.php @@ -0,0 +1,14 @@ +@extends('layouts.app') + +@section('title', 'ログイン') + +@section('content') +

ログイン

+ +
+ @csrf +

+

+ +
+@endsection diff --git a/src/routes/web.php b/src/routes/web.php index 0f25021..3006ece 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Http\Controllers\LoginController; use App\Http\Controllers\RegisterController; use Illuminate\Support\Facades\Route; @@ -20,6 +21,8 @@ Route::view('/register', 'register')->name('registerForm'); Route::post('/register', RegisterController::class)->name('register'); +Route::view('/login', 'login')->name('loginForm'); +Route::post('/login', LoginController::class)->name('login'); Route::group(['middleware' => 'auth'], static function () {