1
I would like to allow access to some pages only if user is logged in.
I did so:
Route::group( ['middleware' => 'usuario'], function (){
/* Minhas páginas */
});
So far so good, but I would like to check if the password is already current (if sn_senha_atual == 'S' )
I thought of using nested middleware, but it gives a mistake ERR_TOO_MANY_REDIRECTS when trying to use like this:
Route::group( ['middleware' => 'usuario'], function (){
Route::group( ['middleware' => 'senha'], function (){
/* minhas paginas */
});
});
My middleware user is like this:
public function handle($request, Closure $next)
{
if( !Auth::check() ){
return redirect()->back();
}
return $next($request);
}
And my middleware password is like this:
public function handle($request, Closure $next)
{
$user = Auth::user();
if( $user->sn_senha_atual == 'N' ){
// echo "Alterar id: ".$user->id;
return redirect()->route( 'usu.alterar');
}
return $next($request);
}
How do I so that after checking if user is logged in, check if the password is the current one?
[EDIT 1]
Put the change page outside the password middlware, but now it seems that user middleware does not let pass
Route::group( ['middleware' => 'usuario'], function (){
Route::group( ['middleware' => 'senha'], function (){
Route::group(['as' => 'usu.', 'prefix' => 'usuario'], function (){
Route::get('',['as' => 'index','middleware' => 'senha', 'uses' => 'UsuarioController@index']);
Route::get('cadastrar',['as' => 'create', 'uses' => 'UsuarioController@create']);
Route::post('salvar',['as' => 'store', 'uses' => 'UsuarioController@store']);
Route::post('delete',['as' => 'remove', 'uses' => 'UsuarioController@remove']);
Route::post('edit',['as' => 'edit', 'uses' => 'UsuarioController@edit']);
Route::post('update',['as' => 'update', 'uses' => 'UsuarioController@update']);
Route::get('sair',['as' => 'sair','middleware' => 'senha', 'uses' => 'UsuarioController@sair']);
Route::get('logoff',['as' => 'logoff', 'uses' => 'UsuarioController@logOff']);
});
});
Route::post('alterar',['as' => 'alterar', 'uses' => 'UsuarioController@alterarSenha']);
});
And by chance the pages you’re redirecting to are not within the group that owns the middleware?
– Woss
They’re not, they’re in a simple group, for example :
Route::group(['as' => 'item.', 'prefix' => 'item'], function (){– adventistaam
This syntax of multiples middleware is consistent with the documentation?
– Woss
Route::middleware(['first', 'second'])->group(function () {That way you’re saying $Required Parameter $callback Missing– adventistaam
So also gave the same mistake:
Route::group( ['middleware' => ['usuario', 'senha']]– adventistaam
Next you should ta doing so, the password check middlweare must be contained in the route
us.alterar, so he checks again and tells you to go to the same page, that’s what you can’t do, what you have to do is take the routeus.alterarthemiddlewarepassword ... understood?– novic
I really took inside and did not give the message anymore, however, it does not enter the page to change.
– adventistaam
because it should be get and not post changes it!
– novic
Yeah. It worked. That’s what it was.. I put it out of all the groups and it worked. Please add as a response
– adventistaam
@adventistaam can add yourself and put a text explaining what happened... !!! it’s cool to reply too! go there
– novic