ldc-cocotte/app/Http/Controllers/Fo/Customers/PasswordController.php
Jérémy Munsch b36d070db1
feat(crm): implement customer password update functionality
Adds the ability for customers to update their passwords through a new action and input/output classes.
2026-10-27 09:58:35 +01:00

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Fo\Customers;
use App\Actions\Crm\UpdateCustomerPassword;
use App\Contracts\Executor;
use App\Http\Controllers\Controller;
use App\Http\Requests\Fo\Customer\UpdatePasswordRequest;
use App\Models\Customer;
use Domain\Models\ValueObjects\CrmCustomer;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\ValidationException;
class PasswordController extends Controller
{
public function __construct(
private readonly Executor $executor
) {
}
public function editPassword(): View
{
$this->authorize('manageOwnProfile', Customer::class);
return view('fo.customer.edit.password');
}
public function editPasswordSubmit(UpdatePasswordRequest $request, UpdateCustomerPassword $updateCustomerPassword): RedirectResponse
{
$this->authorize('manageOwnProfile', Customer::class);
$result = $this->executor->execute(
$updateCustomerPassword,
$request->toUpdateCustomerPasswordInput()
);
return match (true) {
$result->result instanceof CrmCustomer => back()
->with('success', trans('Password updated')),
$result->result instanceof ValidationException => back()
->withErrors($result->result->errors()),
$result->result === false => back()
->withErrors(trans('An error occurred, please try again later.')),
};
}
}