66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Fo\Auth;
|
|
|
|
use App\Models\Customer;
|
|
use Illuminate\Contracts\Auth\PasswordBroker;
|
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Password;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
|
|
|
class ResetPasswordController extends AuthController
|
|
{
|
|
use ResetsPasswords;
|
|
|
|
public function __construct(
|
|
private readonly AppCustomerAuthService $authService
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function showResetForm(Request $request): View
|
|
{
|
|
$token = $request->route()?->parameter('token');
|
|
|
|
return view('fo.auth.passwords.reset')->with(
|
|
['token' => $token, 'email' => $request->email]
|
|
);
|
|
}
|
|
|
|
protected function setUserPassword(Customer $customer, string $password): void
|
|
{
|
|
$result = $this->authService->resetPasswordFor($customer, $password);
|
|
|
|
if ($result instanceof ValidationException) {
|
|
throw ValidationException::withMessages([
|
|
'error' => sprintf(
|
|
'%s : %s',
|
|
trans('validation.attributes.password'),
|
|
$result->getMessage()
|
|
),
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function broker(): PasswordBroker
|
|
{
|
|
return Password::broker('customers');
|
|
}
|
|
|
|
protected function guard(): StatefulGuard
|
|
{
|
|
return Auth::guard('frontend');
|
|
}
|
|
|
|
protected function redirectTo(): string
|
|
{
|
|
return route('fo.pages.home');
|
|
}
|
|
}
|