2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
2019-05-20 07:37:41 +02:00
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
2021-12-02 13:15:53 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
|
|
use Illuminate\Support\Facades\Route;
|
2019-05-20 07:37:41 +02:00
|
|
|
|
|
|
|
class RouteServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* The path to the "home" route for your application.
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
2021-12-02 13:15:53 +01:00
|
|
|
* This is used by Laravel authentication to redirect users after login.
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2021-12-02 13:15:53 +01:00
|
|
|
public const HOME = '/accounts';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The controller namespace for the application.
|
|
|
|
*
|
|
|
|
* When present, controller route declarations will automatically be prefixed with this namespace.
|
|
|
|
*
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2019-05-20 07:37:41 +02:00
|
|
|
protected $namespace = 'App\Http\Controllers';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define your route model bindings, pattern filters, etc.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2021-10-03 11:35:09 +02:00
|
|
|
Route::pattern('settingName', '[a-zA-Z]+');
|
2021-12-02 13:15:53 +01:00
|
|
|
$this->configureRateLimiting();
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
$this->routes(function () {
|
|
|
|
Route::prefix('api/v1')
|
|
|
|
->middleware('api.v1')
|
2022-09-07 17:54:27 +02:00
|
|
|
->namespace($this->getApiNamespace('1'))
|
2021-12-02 13:15:53 +01:00
|
|
|
->group(base_path('routes/api/v1.php'));
|
2021-11-04 23:57:23 +01:00
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
// Route::prefix('api/v2')
|
|
|
|
// ->middleware('api.v2')
|
|
|
|
// ->namespace($this->getApiNamespace(2))
|
|
|
|
// ->group(base_path('routes/api/v2.php'));
|
2019-05-20 07:37:41 +02:00
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
Route::middleware('web')
|
|
|
|
->namespace($this->namespace)
|
|
|
|
->group(base_path('routes/web.php'));
|
|
|
|
});
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* Build Api namespace based on provided version
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
2021-12-02 13:15:53 +01:00
|
|
|
* @return string The Api namespace
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
2022-08-26 15:57:18 +02:00
|
|
|
private function getApiNamespace(string $version)
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2021-12-02 13:15:53 +01:00
|
|
|
return 'App\Api\v' . $version . '\Controllers';
|
2021-11-04 23:57:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* Configure the rate limiters for the application.
|
2021-11-04 23:57:23 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-12-02 13:15:53 +01:00
|
|
|
protected function configureRateLimiting()
|
2021-11-04 23:57:23 +01:00
|
|
|
{
|
2021-12-02 13:15:53 +01:00
|
|
|
RateLimiter::for('api', function (Request $request) {
|
2023-03-16 15:57:22 +01:00
|
|
|
$maxAttempts = config('2fauth.api.throttle');
|
|
|
|
return is_null($maxAttempts) ? Limit::none() : Limit::perMinute($maxAttempts)->by($request->ip());
|
2021-12-02 13:15:53 +01:00
|
|
|
});
|
2019-05-20 07:37:41 +02:00
|
|
|
}
|
|
|
|
}
|