Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ucan-lab committed Jun 30, 2023
1 parent b3e1b4a commit 9caff54
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/Http/Controllers/ChangePasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Aws\CognitoIdentityProvider\AdminSetUserPassword\AdminSetUserPassword;
use App\Aws\CognitoIdentityProvider\AdminSetUserPassword\AdminSetUserPasswordPayload;
use App\Http\Requests\ChangePasswordRequest;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

final class ChangePasswordController
{
public function __invoke(ChangePasswordRequest $request, AdminSetUserPassword $adminSetUserPassword, User $user): RedirectResponse
{
$payload = AdminSetUserPasswordPayload::createForPermanent($request->username(), $request->password());
$adminSetUserPassword->execute($payload);

Auth::login($user);
Session::regenerate();
Session::regenerateToken();

return redirect()->route('dashboard');
}
}
28 changes: 28 additions & 0 deletions src/app/Http/Requests/ChangePasswordRequest.php
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 ChangePasswordRequest 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');
}
}
14 changes: 14 additions & 0 deletions src/resources/views/force-password-change.blade.php
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
4 changes: 4 additions & 0 deletions src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
Route::view('/login', 'login')->name('loginForm');
Route::post('/login', LoginController::class)->name('login');

Route::group(['middleware' => 'signed'], static function () {
Route::view('/change-password/{user}', 'change-password')->name('changePasswordForm');
Route::post('/change-password/{user}', LogoutController::class)->name('changePassword');
});

Route::group(['middleware' => 'auth'], static function () {
Route::view('/dashboard', 'dashboard')->name('dashboard');
Expand Down

0 comments on commit 9caff54

Please sign in to comment.