2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Fo\Customers;
|
|
|
|
|
|
2026-09-30 10:01:52 +02:00
|
|
|
use App\Actions\Crm\UpdateCustomerPassword;
|
|
|
|
|
use App\Contracts\Executor;
|
2026-06-14 21:32:07 +02:00
|
|
|
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;
|
2026-09-30 10:01:52 +02:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
class PasswordController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2026-09-30 10:01:52 +02:00
|
|
|
private readonly Executor $executor
|
2026-06-14 21:32:07 +02:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function editPassword(): View
|
|
|
|
|
{
|
|
|
|
|
$this->authorize('manageOwnProfile', Customer::class);
|
|
|
|
|
|
|
|
|
|
return view('fo.customer.edit.password');
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 10:01:52 +02:00
|
|
|
public function editPasswordSubmit(UpdatePasswordRequest $request, UpdateCustomerPassword $updateCustomerPassword): RedirectResponse
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
|
|
|
|
$this->authorize('manageOwnProfile', Customer::class);
|
|
|
|
|
|
2026-09-30 10:01:52 +02:00
|
|
|
$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.')),
|
|
|
|
|
};
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
}
|