ldc-boutique-cnc-sable/app/Http/Controllers/Fo/Auth/AuthController.php
2026-10-27 09:58:12 +01:00

67 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Fo\Auth;
use App\Http\Controllers\Controller;
use App\Models\Customer;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\URL;
abstract class AuthController extends Controller
{
public function __construct()
{
// @phpstan-ignore assign.propertyType
ResetPassword::$createUrlCallback = $this->createResetUrl(...);
VerifyEmail::$createUrlCallback = $this->createValidationUrl(...);
}
public function createValidationUrl(Customer $notifiable): string
{
$appKey = Config::string('app.key');
if (empty(trim($appKey))) {
throw new \UnexpectedValueException('App key is not set.');
}
return url(
URL::temporarySignedRoute(
'fo.auth.verification.verify',
Date::now()->addMinutes(Config::integer(
'auth.verification.expire',
60
)),
[
'id' => $notifiable->getKey(),
'hash' => hash_hmac(
'sha256',
$notifiable->getEmailForVerification(),
$appKey
),
],
false
)
);
}
public function createResetUrl(Customer $notifiable, string $token): string
{
return url(
URL::temporarySignedRoute(
'fo.auth.reset-password',
Date::now()->addMinutes(Config::integer('auth.reset.expire', 60)),
[
'token' => $token,
'email' => $notifiable->getEmailForPasswordReset(),
],
false
)
);
}
}