I'd like to allow access to a few pages only if the user is logged in.
I did so:
Route::group( ['middleware' => 'usuario'], function (){
/* Minhas páginas */
});
So far so good, but I'd like to check if the password is already the current one (if sn_senha_atual == 'S'
)
I thought about using nested middlewares, however it gives an ERR_TOO_MANY_REDIRECTS error when trying to use it like this:
Route::group( ['middleware' => 'usuario'], function (){
Route::group( ['middleware' => 'senha'], function (){
/* minhas paginas */
});
});
My user middleware looks like this:
public function handle($request, Closure $next)
{
if( !Auth::check() ){
return redirect()->back();
}
return $next($request);
}
And my middleware password looks 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 check if the user is logged in, check if the password is the current one?
[EDIT 1]
Put the change page out of 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']);
});