在laravel中哪里可以找到Auth :: attempt方法

时间:2018-08-28 17:32:16

标签: php laravel

除了我的Laravel项目中用户的电子邮件和密码外,我还想为身份验证查询添加其他条件

我在laravel官方文档中阅读了此内容。 https://laravel.com/docs/5.6/authentication

  

指定附加条件如果您愿意,还可以添加附加条件   验证查询的条件,除了用户的   电子邮件和密码。例如,我们可以验证用户是否被标记为   “有效”:

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
    // The user is active, not suspended, and exists.
}

在哪里可以找到这种方法?

4 个答案:

答案 0 :(得分:2)

您需要在LoginController中登录方法

public function login(\Illuminate\Http\Request $request) {
    $this->validateLogin($request);

    // If the class is using the ThrottlesLogins trait, we can automatically throttle
    // the login attempts for this application. We'll key this by the username and
    // the IP address of the client making these requests into this application.
    if ($this->hasTooManyLoginAttempts($request)) {
        $this->fireLockoutEvent($request);
        return $this->sendLockoutResponse($request);
    }

    // This section is the only change
    if ($this->guard()->validate($this->credentials($request))) {
        $user = $this->guard()->getLastAttempted();

        // Make sure the user is active
        if ($user->active && $this->attemptLogin($request)) {
            // Send the normal successful login response
            return $this->sendLoginResponse($request);
        } else {
            // Increment the failed login attempts and redirect back to the
            // login form with an error message.
            $this->incrementLoginAttempts($request);
            return redirect()
                ->back()
                ->withInput($request->only($this->username(), 'remember'))
                ->withErrors(['active' => 'You must be active to login.']);
        }
    }

    // If the login attempt was unsuccessful we will increment the number of attempts
    // to login and redirect the user back to the login form. Of course, when this
    // user surpasses their maximum number of attempts they will get locked out.
    $this->incrementLoginAttempts($request);

    return $this->sendFailedLoginResponse($request);
}

这对我有用

答案 1 :(得分:1)

如果使用Laravel提供的身份验证支架,它将位于AuthenticatesUsers特性中:

/**
 * Attempt to log the user into the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return bool
 */
protected function attemptLogin(Request $request)
{
    return $this->guard()->attempt(
        $this->credentials($request), $request->filled('remember')
    );
}

您可以在LoginController中覆盖此方法。

答案 2 :(得分:1)

您正在呼叫的

Auth::attempt很可能是Illuminate\Auth\SessionGuard@attempt

路径:

Auth::attempt -> Illuminate\Auth\AuthManager -> (guard) Illuminate\Auth\SessionGuard

Facade -> Illuminate\Auth\AuthManager@call -> @guard -> Illuminate\Auth\SessionGuard@attempt

Laravel 5.6 Docs - Facades - Class Reference

为了能够调整为LoginController传递的凭据,您只需要覆盖1个方法credentials,因为它是传递给{{1}的数组所涉及的唯一方法}。

attempt

答案 3 :(得分:0)

AuthController.php

do_install_append() {
    cmake --system-information | grep CMAKE_ROOT | cut -d \" -f2
    install -d ${D}/$CMAKE_ROOT}/Modules
    install ${S}/FindCoAP.cmake ${D}/$CMAKE_ROOT}/Modules
}

这是您要找的那个吗?