简体   繁体   English

具有特定数据库记录的Laravel登录限制

[英]Laravel login limit with specific database record

I'm trying to limit users that have "Request" in the function row of the user table in the database from logging in. 我正在尝试限制在数据库中用户表的功能行中具有“请求”的用户登录。

AuthenticatesUsers.php AuthenticatesUsers.php

protected function attemptLogin(Request $request)
{
    return $this->guard()->attempt(
        $this->credentials($request), $request->has('remember')
    );
}

How would I go about to accomplish this? 我将如何实现这一目标?

if (Auth::attempt([
    'email' => $request->email, 
    'password' => $request->password, 
    'function' => 'Request'
])) {

    //only users matching those 3 criteria will be logged in.
}

In what file does this go? 这是什么文件?

  • Any controller where you do user login logic (UserController, LoginController, AuthController or whatever you call it). 任何用户登录逻辑的控制器(UserController,LoginController,AuthController或其他任何你称之为的控制器)。

    You cannot add this to the default login unless you did it to change it. 除非您更改它,否则无法将其添加到默认登录名。 This is custom/manual autentication. 这是自定义/手动验证。

So i can not restrict people from loggin in with the default authentication from laravel? 所以我不能用laravel的默认身份验证来限制人们登录?

  • No, that's why they give you manual authentication like what I did so you can restrict anything you want. 不,这就是为什么他们像我一样给你手动认证,所以你可以限制你想要的任何东西。 The default auth, you cannot customize everything there. 默认身份验证,您无法自定义那里的所有内容。 It's limited. 它有限。 For people who just want to get going without too much adaptation. 对于那些只想在没有太多改编的情况下开始的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM