admin icon indicating copy to clipboard operation
admin copied to clipboard

How to disable admin?

Open eugenem opened this issue 9 years ago • 5 comments

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...

eugenem avatar Feb 21 '16 13:02 eugenem

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

Badou90 avatar Feb 24 '16 00:02 Badou90

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

eugenem avatar Feb 24 '16 09:02 eugenem

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

Badou90 avatar Feb 25 '16 01:02 Badou90

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);
    }

}

eugenem avatar Mar 08 '16 23:03 eugenem

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

butschster avatar Mar 26 '16 10:03 butschster