File tree Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace App \Http \Controllers ;
6
+
7
+ use Acme \Domain \User \Username ;
8
+ use Acme \Domain \User \UserRepository ;
9
+ use App \Aws \CognitoIdentityProvider \AdminInitiateAuth \AdminInitiateAuth ;
10
+ use App \Aws \CognitoIdentityProvider \AdminInitiateAuth \AdminInitiateAuthPayload ;
11
+ use App \Http \Requests \LoginRequest ;
12
+ use Illuminate \Http \RedirectResponse ;
13
+ use Illuminate \Support \Facades \Auth ;
14
+ use Illuminate \Support \Facades \Session ;
15
+
16
+ final readonly class LoginController
17
+ {
18
+ public function __construct (
19
+ private UserRepository $ userRepository ,
20
+ private AdminInitiateAuth $ adminInitiateAuth ,
21
+ ) {
22
+ }
23
+
24
+ public function __invoke (LoginRequest $ request , AdminInitiateAuth $ adminInitiateAuth ): RedirectResponse
25
+ {
26
+ $ user = $ this ->userRepository ->findByUsername (new Username ($ request ->username ()));
27
+
28
+ $ payload = AdminInitiateAuthPayload::createForAdminUserPasswordAuthFlow ($ user ->username (), $ request ->password ());
29
+ $ this ->adminInitiateAuth ->execute ($ payload );
30
+
31
+ Auth::loginUsingId ($ user ->userId ());
32
+ Session::regenerate ();
33
+ Session::regenerateToken ();
34
+
35
+ return redirect ()->route ('dashboard ' );
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace App \Http \Requests ;
6
+
7
+ use Illuminate \Foundation \Http \FormRequest ;
8
+
9
+ final class LoginRequest extends FormRequest
10
+ {
11
+ public function rules (): array
12
+ {
13
+ return [
14
+ 'username ' => ['required ' , 'string ' ],
15
+ 'password ' => ['required ' , 'string ' ],
16
+ ];
17
+ }
18
+
19
+ public function username (): string
20
+ {
21
+ return $ this ->input ('username ' );
22
+ }
23
+
24
+ public function password (): string
25
+ {
26
+ return $ this ->input ('password ' );
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ @extends (' layouts.app' )
2
+
3
+ @section (' title' , ' ログイン' )
4
+
5
+ @section (' content' )
6
+ <h1 >ログイン</h1 >
7
+
8
+ <form action =" {{ route (' login' ) } }" method =" POST" >
9
+ @csrf
10
+ <p ><label >ユーザー名: <input type =" text" name =" username" ></label ></p >
11
+ <p ><label >パスワード: <input type =" password" name =" password" ></label ></p >
12
+ <button type =" submit" >ログイン</button >
13
+ </form >
14
+ @endsection
Original file line number Diff line number Diff line change 2
2
3
3
declare (strict_types=1 );
4
4
5
+ use App \Http \Controllers \LoginController ;
5
6
use App \Http \Controllers \RegisterController ;
6
7
use Illuminate \Support \Facades \Route ;
7
8
20
21
21
22
Route::view ('/register ' , 'register ' )->name ('registerForm ' );
22
23
Route::post ('/register ' , RegisterController::class)->name ('register ' );
24
+ Route::view ('/login ' , 'login ' )->name ('loginForm ' );
25
+ Route::post ('/login ' , LoginController::class)->name ('login ' );
23
26
24
27
25
28
Route::group (['middleware ' => 'auth ' ], static function () {
You can’t perform that action at this time.
0 commit comments