Added a new feature to allow users to update their passwords.
This commit is contained in:
parent
00a0624eea
commit
39eae7f196
17
app/Dto/Request/Private/Profile/UpdatePassword.php
Normal file
17
app/Dto/Request/Private/Profile/UpdatePassword.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Dto\Request\Private\Profile;
|
||||
|
||||
use App\Dto\Request\Dto;
|
||||
|
||||
final readonly class UpdatePassword extends Dto
|
||||
{
|
||||
public function __construct(
|
||||
private string $password
|
||||
) { }
|
||||
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Private;
|
||||
|
||||
use App\Http\Requests\Private\Profile\UpdatePasswordRequest;
|
||||
use App\Http\Requests\Private\Profile\UpdateRequest;
|
||||
use App\Services\Private\ProfileService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@ -39,4 +40,16 @@ final class ProfileController extends Controller
|
||||
}
|
||||
return redirect()->route('profile.edit')->withSuccess($result->getMessage());
|
||||
}
|
||||
|
||||
public function updatePassword(UpdatePasswordRequest $request): RedirectResponse
|
||||
{
|
||||
$data = $request->getDto();
|
||||
$user = $request->user();
|
||||
|
||||
$result = $this->profileService->updatePassword($data, $user);
|
||||
if ($result->isError()) {
|
||||
return redirect()->back()->withInput()->withErrors($result->getMessage());
|
||||
}
|
||||
return redirect()->route('profile.edit')->withSuccess($result->getMessage());
|
||||
}
|
||||
}
|
||||
|
26
app/Http/Requests/Private/Profile/UpdatePasswordRequest.php
Normal file
26
app/Http/Requests/Private/Profile/UpdatePasswordRequest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Private\Profile;
|
||||
|
||||
use App\Contracts\FormRequestDto;
|
||||
use App\Dto\Request\Private\Profile\UpdatePassword;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
final class UpdatePasswordRequest extends FormRequest implements FormRequestDto
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'password' => ['required', 'confirmed', Password::default()],
|
||||
];
|
||||
}
|
||||
|
||||
public function getDto(): UpdatePassword
|
||||
{
|
||||
return new UpdatePassword(password: $this->input('password'));
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services\Private;
|
||||
|
||||
use App\Dto\Request\Private\Profile\Update;
|
||||
use App\Dto\Request\Private\Profile\UpdatePassword;
|
||||
use App\Models\User;
|
||||
use App\ServiceResults\ServiceResultError;
|
||||
use App\ServiceResults\ServiceResultSuccess;
|
||||
@ -28,4 +29,15 @@ final class ProfileService extends Service
|
||||
}
|
||||
return $this->ok(__('Profile saved successfully'));
|
||||
}
|
||||
|
||||
public function updatePassword(UpdatePassword $update, User $user): ServiceResultError | ServiceResultSuccess
|
||||
{
|
||||
try {
|
||||
$this->userCommandHandler->handleUpdatePassword($user, $update->getPassword());
|
||||
} catch (\Throwable $e) {
|
||||
report($e->getMessage());
|
||||
return $this->errService($e->getMessage());
|
||||
}
|
||||
return $this->ok(__('The password has been changed'));
|
||||
}
|
||||
}
|
||||
|
@ -44,5 +44,6 @@
|
||||
"Settings": "Settings",
|
||||
"Dashboard": "Dashboard",
|
||||
"Save": "Save",
|
||||
"Profile saved successfully": "Profile saved successfully"
|
||||
"Profile saved successfully": "Profile saved successfully",
|
||||
"The password has been changed": "The password has been changed"
|
||||
}
|
||||
|
@ -44,5 +44,6 @@
|
||||
"Settings": "Настройки",
|
||||
"Dashboard": "Dashboard",
|
||||
"Save": "Сохранить",
|
||||
"Profile saved successfully": "Профиль успешно сохранен"
|
||||
"Profile saved successfully": "Профиль успешно сохранен",
|
||||
"The password has been changed": "Пароль был изменен"
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
<div class="col-12 mb-4">
|
||||
<div class="card border-0 shadow components-section">
|
||||
<div class="card-body">
|
||||
<form method="post" {{ route('profile.update-password') }}>
|
||||
<form method="post" action="{{ route('profile.update-password') }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<x-private.forms.input :title="__('validation.attributes.password')" name="password" type="password" required />
|
||||
|
Loading…
Reference in New Issue
Block a user