refactor(Helpers): update parameter types and remove ignores refactor(Models): streamline order assignment logic refactor(Enums): clarify unused constant warnings refactor(Services): encapsulate cutoff week offset logic
69 lines
2 KiB
PHP
69 lines
2 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()
|
|
{
|
|
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(mixed $notifiable, string $token): string
|
|
{
|
|
if (! is_object($notifiable) || ! ($notifiable instanceof Customer)) {
|
|
throw new \InvalidArgumentException('Invalid notifiable provided.');
|
|
}
|
|
|
|
return url(
|
|
URL::temporarySignedRoute(
|
|
'fo.auth.reset-password',
|
|
Date::now()->addMinutes(Config::integer('auth.reset.expire', 60)),
|
|
[
|
|
'token' => $token,
|
|
'email' => $notifiable->getEmailForPasswordReset(),
|
|
],
|
|
false
|
|
)
|
|
);
|
|
}
|
|
}
|