ldc-cocotte/app/Http/Controllers/Fo/Customers/PasswordController.php

50 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Fo\Customers;
use App\Contracts\Executor;
use App\Cqs\Actions\Crm\UpdateCustomerPassword;
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;
use Illuminate\Validation\ValidationException;
2026-06-14 21:32:07 +02:00
class PasswordController extends Controller
{
public function __construct(
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');
}
public function editPasswordSubmit(UpdatePasswordRequest $request, UpdateCustomerPassword $updateCustomerPassword): RedirectResponse
2026-06-14 21:32:07 +02:00
{
$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.')),
};
2026-06-14 21:32:07 +02:00
}
}