Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable admin? #329

Open
eugenem opened this issue Feb 21, 2016 · 5 comments
Open

How to disable admin? #329

eugenem opened this issue Feb 21, 2016 · 5 comments

Comments

@eugenem
Copy link

eugenem commented Feb 21, 2016

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
Copy link

Badou90 commented Feb 24, 2016

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

@eugenem
Copy link
Author

eugenem commented Feb 24, 2016

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

@Badou90
Copy link

Badou90 commented Feb 25, 2016

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
Copy link
Author

eugenem commented Mar 8, 2016

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
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants