diff --git a/app/Dto/Request/Private/Profile/UpdatePassword.php b/app/Dto/Request/Private/Profile/UpdatePassword.php new file mode 100644 index 0000000..8f6fe23 --- /dev/null +++ b/app/Dto/Request/Private/Profile/UpdatePassword.php @@ -0,0 +1,17 @@ +password; + } +} diff --git a/app/Http/Controllers/Private/ProfileController.php b/app/Http/Controllers/Private/ProfileController.php index be63f7f..3f3eea9 100644 --- a/app/Http/Controllers/Private/ProfileController.php +++ b/app/Http/Controllers/Private/ProfileController.php @@ -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()); + } } diff --git a/app/Http/Requests/Private/Profile/UpdatePasswordRequest.php b/app/Http/Requests/Private/Profile/UpdatePasswordRequest.php new file mode 100644 index 0000000..bb7a12e --- /dev/null +++ b/app/Http/Requests/Private/Profile/UpdatePasswordRequest.php @@ -0,0 +1,26 @@ + ['required', 'confirmed', Password::default()], + ]; + } + + public function getDto(): UpdatePassword + { + return new UpdatePassword(password: $this->input('password')); + } +} diff --git a/app/Services/Private/ProfileService.php b/app/Services/Private/ProfileService.php index 080c090..4a71184 100644 --- a/app/Services/Private/ProfileService.php +++ b/app/Services/Private/ProfileService.php @@ -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')); + } } diff --git a/lang/en.json b/lang/en.json index 803e73b..6431b8a 100644 --- a/lang/en.json +++ b/lang/en.json @@ -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" } diff --git a/lang/ru.json b/lang/ru.json index 8602520..da44446 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -44,5 +44,6 @@ "Settings": "Настройки", "Dashboard": "Dashboard", "Save": "Сохранить", - "Profile saved successfully": "Профиль успешно сохранен" + "Profile saved successfully": "Профиль успешно сохранен", + "The password has been changed": "Пароль был изменен" } diff --git a/resources/views/private/profile/profile.blade.php b/resources/views/private/profile/profile.blade.php index 608c13a..838f10c 100644 --- a/resources/views/private/profile/profile.blade.php +++ b/resources/views/private/profile/profile.blade.php @@ -20,7 +20,7 @@