initial Commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Database\Db2\Db2Connection;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PDO;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
DB::extend('odbc', function (array $config, string $name) {
|
||||
$pdo = new PDO(
|
||||
'odbc:' . ($config['dsn'] ?? 'MEDIUK'),
|
||||
$config['username'] ?? '',
|
||||
$config['password'] ?? '',
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
|
||||
]
|
||||
);
|
||||
|
||||
$schema = $config['schema'] ?? null;
|
||||
|
||||
if ($schema) {
|
||||
if (!preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $schema)) {
|
||||
throw new \InvalidArgumentException('Invalid Db2 schema');
|
||||
}
|
||||
|
||||
$pdo->exec('SET CURRENT SCHEMA ' . $schema);
|
||||
}
|
||||
|
||||
$config['name'] = $name;
|
||||
|
||||
return new Db2Connection(
|
||||
$pdo,
|
||||
$config['database'] ?? '',
|
||||
$config['prefix'] ?? '',
|
||||
$config
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
\DB::connection('db2_local')->beforeExecuting(
|
||||
function ($sql, $bindings, $connection) {
|
||||
logger()->debug('DB2 BEFORE EXECUTE', [
|
||||
'sql' => $sql,
|
||||
'bindings_count' => count($bindings),
|
||||
]);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Actions\Fortify\CreateNewUser;
|
||||
use App\Actions\Fortify\ResetUserPassword;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Fortify\Fortify;
|
||||
|
||||
class FortifyServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->configureActions();
|
||||
$this->configureViews();
|
||||
$this->configureRateLimiting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Fortify actions.
|
||||
*/
|
||||
private function configureActions(): void
|
||||
{
|
||||
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
|
||||
Fortify::createUsersUsing(CreateNewUser::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Fortify views.
|
||||
*/
|
||||
private function configureViews(): void
|
||||
{
|
||||
Fortify::loginView(fn () => view('livewire.auth.login'));
|
||||
Fortify::verifyEmailView(fn () => view('livewire.auth.verify-email'));
|
||||
Fortify::twoFactorChallengeView(fn () => view('livewire.auth.two-factor-challenge'));
|
||||
Fortify::confirmPasswordView(fn () => view('livewire.auth.confirm-password'));
|
||||
Fortify::registerView(fn () => view('livewire.auth.register'));
|
||||
Fortify::resetPasswordView(fn () => view('livewire.auth.reset-password'));
|
||||
Fortify::requestPasswordResetLinkView(fn () => view('livewire.auth.forgot-password'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rate limiting.
|
||||
*/
|
||||
private function configureRateLimiting(): void
|
||||
{
|
||||
RateLimiter::for('two-factor', function (Request $request) {
|
||||
return Limit::perMinute(5)->by($request->session()->get('login.id'));
|
||||
});
|
||||
|
||||
RateLimiter::for('login', function (Request $request) {
|
||||
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
|
||||
|
||||
return Limit::perMinute(5)->by($throttleKey);
|
||||
});
|
||||
|
||||
RateLimiter::for('passkeys', function (Request $request) {
|
||||
$credentialId = $request->input('credential.id');
|
||||
|
||||
return Limit::perMinute(10)->by(
|
||||
($credentialId ?: $request->session()->getId()).'|'.$request->ip(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user