sleeping-owl / admin

Administrative interface builder for Laravel
http://sleeping-owl.github.io/
MIT License
503 stars 260 forks source link

How to disable admin? #329

Open eugenem opened 8 years ago

eugenem commented 8 years ago

I've got custom Admin model (v3) that has is_active field. I can edit admins nicely using the admin forms. Question is: how do I add check for is_active = 1 to login process? I want to be able to disable some admins without deleting them...

Badou90 commented 8 years ago

add a middleware which will check your field and then add this to middleware group or admin config

eugenem commented 8 years ago

Would you mind to detail that? I'm not so good in middlewares...

Badou90 commented 8 years ago

you can generate middleware with artisan, and inside just check using your facade (in my case it's AdminAuth) if your user field is_active is false and return abort(403) or redirect, or whatever you want

eugenem commented 8 years ago

This is what I've tried, and I'm getting redirect loop after trying to login with disabled user...

class AdminAuthenticate
{
    public function handle($request, Closure $next)
    {
        if ( $request->path() != 'admin/login' && ( AdminAuth::guest() || !AdminAuth::user()->is_active ))
        {
            AdminAuth::logout();
            if ($request->ajax())
            {
                return response('Unauthorized.', 401);
            } else
            {
                return redirect()->guest(route('admin.login'));
            }
        }

        return $next($request);
    }

}
butschster commented 8 years ago

Use https://github.com/LaravelRUS/SleepingOwlAdmin