vendredi 29 mars 2019

Laravel - Redirection if connected

I am a young French developer and I am at a dead end about redirections under Laravel.

I have user tables, namely Client(users) and Employes (admin) and I can log on without problem with a login form that sends me to 2 different pages:

 Connected as a client-> mon-compte,
 Logged in as an employe-> gestion-admin.

However, if I am logged in as a client and I change the url mon-compte by gestion-admin, I have access to this page and vice versa ...

So I set guards and middlewares under Laravel that seem to work but that alternately I will say. In my web.php, I have 2 groups:

Route::group([
'middleware' => 'App\Http\Middleware\Employe',
], function () {
    Route::get('/mon-compte', 'ControllerConnexion@accueilClient');
    Route::view('mon-compte', 'pages/mon-compte');
    Route::get('/gestion-admin', 'ControllerConnexion@redirectClient');
});

Route::group([
'middleware' => 'App\Http\Middleware\Client',
], function () {
    Route::get('/gestion-admin', 'ControllerConnexion@accueilEmploye');
    Route::view('gestion-admin', 'pages/gestion-admin');
    Route::get('/mon-compte', 'ControllerConnexion@redirectEmploye');

});

In this order of position of the groups, the access used is blocked if I change the url /gestion-admin by /mon-compte if I connect as a client, I arrive directly on the gestion-page page . If I change the url and want to go to mon-compte, it sends me back to gestion-admin.

By cons, if I reverse the 2 groups of position:

Route::group([
'middleware' => 'App\Http\Middleware\Client',
], function () {
    Route::get('/gestion-admin', 'ControllerConnexion@accueilEmploye');
    Route::view('gestion-admin', 'pages/gestion-admin');
    Route::get('/mon-compte', 'ControllerConnexion@redirectEmploye');

});

Route::group([
'middleware' => 'App\Http\Middleware\Employe',
], function () {
    Route::get('/mon-compte', 'ControllerConnexion@accueilClient');
    Route::view('mon-compte', 'pages/mon-compte');
    Route::get('/gestion-admin', 'ControllerConnexion@redirectClient');
});

I have the opposite effect ....

I admit that I have no solution.

Aucun commentaire:

Enregistrer un commentaire