Version 0.7.0 #1

Merged
kor-elf merged 90 commits from develop into main 2023-12-08 21:18:23 +06:00
7 changed files with 73 additions and 3 deletions
Showing only changes of commit 39eae7f196 - Show all commits

View 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;
}
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Private; namespace App\Http\Controllers\Private;
use App\Http\Requests\Private\Profile\UpdatePasswordRequest;
use App\Http\Requests\Private\Profile\UpdateRequest; use App\Http\Requests\Private\Profile\UpdateRequest;
use App\Services\Private\ProfileService; use App\Services\Private\ProfileService;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
@ -39,4 +40,16 @@ final class ProfileController extends Controller
} }
return redirect()->route('profile.edit')->withSuccess($result->getMessage()); 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());
}
} }

View 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'));
}
}

View File

@ -3,6 +3,7 @@
namespace App\Services\Private; namespace App\Services\Private;
use App\Dto\Request\Private\Profile\Update; use App\Dto\Request\Private\Profile\Update;
use App\Dto\Request\Private\Profile\UpdatePassword;
use App\Models\User; use App\Models\User;
use App\ServiceResults\ServiceResultError; use App\ServiceResults\ServiceResultError;
use App\ServiceResults\ServiceResultSuccess; use App\ServiceResults\ServiceResultSuccess;
@ -28,4 +29,15 @@ final class ProfileService extends Service
} }
return $this->ok(__('Profile saved successfully')); 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'));
}
} }

View File

@ -44,5 +44,6 @@
"Settings": "Settings", "Settings": "Settings",
"Dashboard": "Dashboard", "Dashboard": "Dashboard",
"Save": "Save", "Save": "Save",
"Profile saved successfully": "Profile saved successfully" "Profile saved successfully": "Profile saved successfully",
"The password has been changed": "The password has been changed"
} }

View File

@ -44,5 +44,6 @@
"Settings": "Настройки", "Settings": "Настройки",
"Dashboard": "Dashboard", "Dashboard": "Dashboard",
"Save": "Сохранить", "Save": "Сохранить",
"Profile saved successfully": "Профиль успешно сохранен" "Profile saved successfully": "Профиль успешно сохранен",
"The password has been changed": "Пароль был изменен"
} }

View File

@ -20,7 +20,7 @@
<div class="col-12 mb-4"> <div class="col-12 mb-4">
<div class="card border-0 shadow components-section"> <div class="card border-0 shadow components-section">
<div class="card-body"> <div class="card-body">
<form method="post" {{ route('profile.update-password') }}> <form method="post" action="{{ route('profile.update-password') }}">
@csrf @csrf
@method('PUT') @method('PUT')
<x-private.forms.input :title="__('validation.attributes.password')" name="password" type="password" required /> <x-private.forms.input :title="__('validation.attributes.password')" name="password" type="password" required />