Php 在身份验证尝试中传递第二个参数后,在登录页上记住用户凭据不起作用

Php 在身份验证尝试中传递第二个参数后,在登录页上记住用户凭据不起作用,php,html,laravel,Php,Html,Laravel,这是一个登录页面,使用artisan命令make::auth创建,并生成了所有必需的代码,但请记住,此登录页面不起作用。 这是登录页面代码 <form id="login-form" method="post" role="form" style="display:@if($errors->has('NotMobileRegisterd')) {{ 'none' }} @else {{ 'block' }} @endif ;" enctype="application/x-www-f

这是一个登录页面,使用artisan命令
make::auth
创建,并生成了所有必需的代码,但请记住,此登录页面不起作用。 这是登录页面代码

<form id="login-form" method="post" role="form" style="display:@if($errors->has('NotMobileRegisterd')) {{ 'none' }} @else {{ 'block' }} @endif ;" enctype="application/x-www-form-urlencoded">
 <input type="hidden" name="_token" value="{{csrf_token()}}">
@if(Session::has('ErrorLogin'))
<div class="alert alert-danger">
  <strong><i class="fa fa-ban"></i></strong> {{ Session::get('ErrorLogin')}}.
</div>
 @endif
<div class="form-group form-group {{ $errors->has('email') ? ' has-error' : '' }}">    
<input type="text" name="email" id="username" tabindex="1" class="form-control" placeholder="Username" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>

<div class="form-group {{ $errors->has('password') ? ' has-error' : '' }}">
<input type="password" name="password" id="password" autocomplete="off" tabindex="2" class="form-control" placeholder="Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
<div class="form-group text-center">
<input type="checkbox" tabindex="3" class="" name="remember_me" id="remember">
<label for="remember"> Remember Me</label>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="submit" id="submit" tabindex="4" class="form-control btn btn-login" value="Log In">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
<a href="{{ route('password.request') }}" tabindex="5" class="forgot-password" >Forgot Password?</a>
</div>
<button type="button" class="btn btn-primary pull-left" onclick="displayOTP()" style="padding-top:10px; padding-bottom:10px;"><i class="fa fa-mobile-alt"> Login with OTP</i></button>
<a href="{{URL::to('auth/google')}}"><button type="button" class="btn btn-danger pull-right" style="padding-top:10px; padding-bottom:10px;"><i class="fa fa-at"> Login with Gmail</i></button></a>
</div>
</div>
</div>
</form>

用户表具有记忆令牌属性,但在从页面注销后仍不记得用户凭据。

我想您可能对Laravel的记忆我功能感到困惑

它不记住用户凭据,而是为登录的用户设置更大的会话时间限制

因此,作为标准,用户将在2小时不活动后注销,并勾选“记住我”框。会话设置为更长的时间,因此您可以离开该站点,5小时后返回,您仍将登录

但如果用户注销,则会话将被破坏

希望这澄清了功能

trait AuthenticatesUsers
{
    use RedirectsUsers, ThrottlesLogins;

    /**
     * Show the application's login form.
     *
     * @return \Illuminate\Http\Response
     */
    public function showLoginForm()
    {
        return view('auth.login');
    }

    /**
     * Handle a login request to the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
     */
    public function login(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);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

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

    /**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required|string',
            'password' => 'required|string',
        ]);
    }

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

    /**
     * Get the needed authorization credentials from the request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    protected function credentials(Request $request)
    {
        return $request->only($this->username(), 'password');
    }

    /**
     * Send the response after the user was authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request);

        return $this->authenticated($request, $this->guard()->user())
                ?: redirect()->intended($this->redirectPath());
    }

    /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        //
    }

    /**
     * Get the failed login response instance.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function sendFailedLoginResponse(Request $request)
    {
        $errors = [$this->username() => trans('auth.failed')];

        if ($request->expectsJson()) {
            return response()->json($errors, 422);
        }

        return redirect()->back()
            ->withInput($request->only($this->username(), 'remember'))
            ->withErrors($errors);
    }

    /**
     * Get the login username to be used by the controller.
     *
     * @return string
     */
    public function username()
    {
        return 'email';
    }

    /**
     * Log the user out of the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {
            $this->guard()->logout();

            $request->session()->invalidate();

            return redirect('/');

    }

    /**
     * Get the guard to be used during authentication.
     *
     * @return \Illuminate\Contracts\Auth\StatefulGuard
     */
    protected function guard()
    {
        return Auth::guard();
    }
}