Novice
Novice

Reputation: 393

Laravel problem with users which are disabled, still can log in

Problem is simple, when user has in table column ````isBlocked``` value 1, cant login. But in my case stil can. I hope so someone find problem which i dont see

App\Middleware\ActiveUser.php

<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Auth;
use Validator,Redirect,Response;
use Closure;

class ActiveUser
{
    public function handle($request, Closure $next)
    {
        if (auth()->check())
        {            
            if (auth()->user()->isBlocked == 1) 
            {
                auth()->logout();
        
                return response(view('expired'));
            }

        } 
    return $next($request);
    }
}

App\Http\Kernel.php

protected $routeMiddleware = [
....
'active_user' => \App\Http\Middleware\ActiveUser::class,
];

web route

Route::group(['middleware' => ['active_user']], function(){
    Route::get('user/{param1}&={param2}', 'AuthController@index')->name('login');
});

Upvotes: 2

Views: 226

Answers (1)

Mustafa Poya
Mustafa Poya

Reputation: 3027

I think the problem is with your condition:

if (Auth::user() && Auth::user()->isBlocked == 1) {
    auth()->logout();
    // you can also abort that user from accessing web pages
    // App::abort(401);
    return response(view('expired'));

   
} else {
    return $next($request);
} 

Upvotes: 1

Related Questions