|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelFlare\Flare\Providers\Edge; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
|
6
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
|
7
|
|
|
|
|
8
|
|
|
class RouteServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* This namespace is applied to the controller routes in your routes file. |
|
12
|
|
|
* |
|
13
|
|
|
* In addition, it is set as the URL generator's root namespace. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $namespace = '\LaravelFlare\Flare\Http\Controllers'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Define your route model bindings, pattern filters, etc. |
|
21
|
|
|
* |
|
22
|
|
|
* @param \Illuminate\Routing\Router $router |
|
23
|
|
|
*/ |
|
24
|
|
|
public function boot(Router $router) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::boot($router); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Define the routes for the application. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Illuminate\Routing\Router $router |
|
33
|
|
|
*/ |
|
34
|
|
|
public function map(Router $router) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->registerMiddleware($router); |
|
37
|
|
|
$this->registerDefinedRoutes($router); |
|
38
|
|
|
$this->registerDefaultRoutes($router); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Register all the Flare Provided Middleware and Middleware Groups. |
|
43
|
|
|
* |
|
44
|
|
|
* We define flarebase rather than extend an existing middleware stack |
|
45
|
|
|
* since it is possible that a user has amended the default middleware |
|
46
|
|
|
* of their application in a way that could break Flare. |
|
47
|
|
|
* |
|
48
|
|
|
* @param Router $router |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function registerMiddleware(Router $router) |
|
51
|
|
|
{ |
|
52
|
|
|
$router->middleware('flareauthenticate', \LaravelFlare\Flare\Http\Middleware\FlareAuthenticate::class); |
|
53
|
|
|
$router->middleware('checkmodelfound', \LaravelFlare\Flare\Http\Middleware\CheckModelFound::class); |
|
54
|
|
|
$router->middleware('checkpermissions', \LaravelFlare\Flare\Http\Middleware\CheckPermissions::class); |
|
55
|
|
|
|
|
56
|
|
|
$router->middlewareGroup('flarebase', [ |
|
57
|
|
|
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, |
|
58
|
|
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class, |
|
59
|
|
|
\App\Http\Middleware\VerifyCsrfToken::class, |
|
60
|
|
|
\App\Http\Middleware\EncryptCookies::class, |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
$router->middlewareGroup('flare', [ |
|
64
|
|
|
'web', |
|
65
|
|
|
'flarebase', |
|
66
|
|
|
'flareauthenticate', |
|
67
|
|
|
'checkpermissions', |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Register the Defined Routes. |
|
73
|
|
|
* |
|
74
|
|
|
* This registers all the routes which have been defined by |
|
75
|
|
|
* Admin sections defined in the Application's Flare Config |
|
76
|
|
|
* (or in the runtime config if anotehr service provider |
|
77
|
|
|
* has already started manipulating these dynamically). |
|
78
|
|
|
* |
|
79
|
|
|
* @param Router $router |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
protected function registerDefinedRoutes(Router $router) |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$router->group( |
|
84
|
|
|
[ |
|
85
|
|
|
'prefix' => \Flare::config('admin_url'), |
|
86
|
|
|
'as' => 'flare::', |
|
87
|
|
|
'middleware' => ['flare'], |
|
88
|
|
|
], |
|
89
|
|
|
function ($router) { |
|
90
|
|
|
\Flare::admin()->registerRoutes($router); |
|
91
|
|
|
$router->get('/', $this->namespace.'\AdminController@getDashboard')->name('dashboard'); |
|
92
|
|
|
} |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Register the Default Routes. |
|
98
|
|
|
* |
|
99
|
|
|
* This registers all the default routes which are included |
|
100
|
|
|
* with Flare. These consist of things which will probably |
|
101
|
|
|
* be included with every application such as the login, |
|
102
|
|
|
* logout and password reset forms. |
|
103
|
|
|
* |
|
104
|
|
|
* The login form can however be hidden by setting the |
|
105
|
|
|
* 'show' config for 'login' to false. |
|
106
|
|
|
* |
|
107
|
|
|
* @param Router $router |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function registerDefaultRoutes(Router $router) |
|
110
|
|
|
{ |
|
111
|
|
|
$router->group( |
|
112
|
|
|
[ |
|
113
|
|
|
'prefix' => \Flare::config('admin_url'), |
|
114
|
|
|
'as' => 'flare::', |
|
115
|
|
|
'middleware' => ['web', 'flarebase'], |
|
116
|
|
|
], |
|
117
|
|
View Code Duplication |
function ($router) { |
|
|
|
|
|
|
118
|
|
|
// Logout route... |
|
119
|
|
|
$router->get('logout', $this->namespace.'\AdminController@getLogout')->name('logout'); |
|
120
|
|
|
|
|
121
|
|
|
if (\Flare::show('login')) { |
|
122
|
|
|
// Login request reoutes... |
|
123
|
|
|
$router->get('login', $this->namespace.'\AdminController@getLogin')->name('login'); |
|
124
|
|
|
$router->post('login', $this->namespace.'\AdminController@postLogin')->name('login'); |
|
125
|
|
|
|
|
126
|
|
|
// Password reset link request routes... |
|
127
|
|
|
$router->get('email', $this->namespace.'\AdminController@getEmail')->name('email'); |
|
128
|
|
|
$router->post('email', $this->namespace.'\AdminController@postEmail')->name('email'); |
|
129
|
|
|
|
|
130
|
|
|
// Password reset routes... |
|
131
|
|
|
$router->get('reset/{token}', $this->namespace.'\AdminController@getReset')->name('reset'); |
|
132
|
|
|
$router->post('reset', $this->namespace.'\AdminController@postReset')->name('reset'); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.