Skip to content

Commit d2c3f0b

Browse files
committed
Routing fixes & automatic route binding.
1 parent 626575d commit d2c3f0b

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed

config/device.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,34 @@
8484

8585
],
8686

87+
/*
88+
|--------------------------------------------------------------------------
89+
| Automatic Route Binding
90+
|--------------------------------------------------------------------------
91+
|
92+
| By default, the package automatically binds the required routes to a
93+
| default HTTP controller. You can switch off automatic registration or
94+
| change the controller name using the options below.
95+
*/
96+
97+
'routing' => [
98+
99+
/**
100+
* Automatically register the default routes to the controller specified below?
101+
* (Routes can also be bound be calling Route::challenge()).
102+
*/
103+
'register' => true,
104+
105+
/**
106+
* Add the following middleware to the automatically registered routes above.
107+
*/
108+
'middleware' => ['web', 'auth'],
109+
110+
/**
111+
* Where should we direct the default authentication routes?
112+
*/
113+
'controller' => \BoxedCode\Laravel\Auth\Device\Http\AuthController::class,
114+
115+
],
116+
87117
];

src/DeviceAuthServiceProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ public function boot()
104104
);
105105

106106
// Register the migrations to publish.
107-
$this->publishes(
108-
[$this->packagePath('migrations') => database_path('migrations')],
109-
'migrations'
110-
);
107+
$this->loadMigrationsFrom($this->packagePath('migrations'));
111108

112109
// Register the event listeners.
113110
$this->app['events']->listen(
@@ -137,6 +134,11 @@ protected function registerRouteMacro()
137134
Router::macro('deviceAuth', function() use ($registerRoutes) {
138135
$registerRoutes();
139136
});
137+
138+
// Register the routes automatically if required.
139+
if ($this->app['config']->get('device.routing.register') === true) {
140+
$registerRoutes();
141+
}
140142
}
141143

142144
/**

src/Http/AuthController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace BoxedCode\Laravel\Auth\Device\Http;
4+
5+
class AuthController extends \Illuminate\Routing\Controller
6+
{
7+
use Traits\DeviceAuthorization;
8+
}

src/Http/routes.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

3-
Route::get('/auth/device/error', 'Auth\DeviceAuthController@showError')->name('device.error');
4-
Route::get('/auth/device/challenge', 'Auth\DeviceAuthController@challenge')->name('device.challenge')->middleware('throttle:10,1');
5-
Route::get('/auth/device/challenged', 'Auth\DeviceAuthController@showChallenged')->name('device.challenged');
6-
Route::get('/auth/device/verify/{token}', 'Auth\DeviceAuthController@verify')->name('device.verify')->middleware('throttle:10,1');
3+
$authMiddleware = config()->get('device.routing.middleware');
4+
5+
Route::middleware($authMiddleware)->group(function () {
6+
$authController = config()->get('device.routing.controller');
7+
8+
Route::get('/auth/device/error', $authController.'@showError')->name('device.error');
9+
Route::get('/auth/device/challenge', $authController.'@challenge')->name('device.challenge')->middleware('throttle:10,1');
10+
Route::get('/auth/device/challenged', $authController.'@showChallenged')->name('device.challenged');
11+
Route::get('/auth/device/verify/{token}', $authController.'@verify')->name('device.verify')->middleware('throttle:10,1');
12+
});

0 commit comments

Comments
 (0)