如何重写Laravel 5.6的默认登录机制? [英] How to override default login mechanism of Laravel 5.6?

查看:168
本文介绍了如何重写Laravel 5.6的默认登录机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当 users 表中的 status 字段设置为 1 时,我才希望用户登录.如果它是 0 ,则只需返回错误消息,说明用户帐户未激活.

I want the user to login only if status field in users table is set to 1. If it is 0 then simply return error stating user account is not active.

因此,在表中创建 status字段之后,我可以在其中检查用户的状态为1,然后仅登录,否则抛出错误.

So after creating the status field in the table, where can I make the check that the user'status is 1 then only login otherwise throw error.

我尝试查找在哪里进行了默认身份验证检查,但在任何地方都找不到它.

I tried to find where the default auth check is made but cannot find it anywhere.

推荐答案

您只需要覆盖AuthenticatesUsers.php中定义的credentials().默认的登录方法使用AuthenticatesUsers特征.因此,请登录控制器并像这样覆盖.

You need to simply override credentials() which is defined in AuthenticatesUsers.php. the default login method use AuthenticatesUsers trait. so go login controller and overwrite like this.

protected function credentials(Request $request)
    {
        return [
            'email'=>$request->{$this->username()},
            'password'=>$request->password,
            'status'=>1

        ];
    }

注意:不要忘记导入Request类,并且不要更改供应商目录中定义的任何内容.

Note: don't forget to import Request class and don't change anything whatever defined in vendor directory.

这篇关于如何重写Laravel 5.6的默认登录机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆