-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Acme\Domain\User\Username; | ||
use Acme\Domain\User\UserRepository; | ||
use App\Aws\CognitoIdentityProvider\AdminInitiateAuth\AdminInitiateAuth; | ||
use App\Aws\CognitoIdentityProvider\AdminInitiateAuth\AdminInitiateAuthPayload; | ||
use App\Http\Requests\LoginRequest; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Session; | ||
|
||
final readonly class LoginController | ||
{ | ||
public function __construct( | ||
private UserRepository $userRepository, | ||
private AdminInitiateAuth $adminInitiateAuth, | ||
) { | ||
} | ||
|
||
public function __invoke(LoginRequest $request, AdminInitiateAuth $adminInitiateAuth): RedirectResponse | ||
{ | ||
$user = $this->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
final class LoginRequest extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'username' => ['required', 'string'], | ||
'password' => ['required', 'string'], | ||
]; | ||
} | ||
|
||
public function username(): string | ||
{ | ||
return $this->input('username'); | ||
} | ||
|
||
public function password(): string | ||
{ | ||
return $this->input('password'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@extends('layouts.app') | ||
|
||
@section('title', 'ログイン') | ||
|
||
@section('content') | ||
<h1>ログイン</h1> | ||
|
||
<form action="{{ route('login') }}" method="POST"> | ||
@csrf | ||
<p><label>ユーザー名: <input type="text" name="username"></label></p> | ||
<p><label>パスワード: <input type="password" name="password"></label></p> | ||
<button type="submit">ログイン</button> | ||
</form> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters