46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(CiSeedCrypto::class, function () {
|
|
$key = (string) config('legacy.seed_user_key_default', '');
|
|
$iv = (string) config('legacy.iv', '');
|
|
|
|
if ($key === '' || $iv === '') {
|
|
throw new \RuntimeException('legacy crypto config missing (seed_user_key_default/iv)');
|
|
}
|
|
|
|
return new CiSeedCrypto($key, $iv);
|
|
});
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
RateLimiter::for('admin-login', function (Request $request) {
|
|
$email = (string) $request->input('email', $request->input('userid', $request->input('admin_email', '')));
|
|
$emailKey = $email !== '' ? mb_strtolower(trim($email)) : 'guest';
|
|
|
|
return [
|
|
Limit::perMinute(10)->by('ip:'.$request->ip()),
|
|
Limit::perMinute(5)->by('admin-login:'.$emailKey),
|
|
];
|
|
});
|
|
|
|
RateLimiter::for('admin-otp', function (Request $request) {
|
|
return [
|
|
Limit::perMinute(10)->by('ip:'.$request->ip()),
|
|
Limit::perMinute(5)->by('admin-otp:'.$request->session()->getId()),
|
|
];
|
|
});
|
|
}
|
|
}
|