我的登录表单中有一个复选框,会在检查时记住用户。我正在使用以下代码,但它对我不起作用:
查看:
@extends('layouts.main')
@section('title') Dashboard
@stop
@section('content')
{{ Form::open(array('url'=>'users/signin', 'class'=>'form-signin')) }}
<h2 class="form-signin-heading">Please Login</h2>
{{ Form::text('email', null, array('class'=>'input-block-level', 'placeholder'=>'Email Address')) }}
{{ Form::password('password', array('class'=>'input-block-level', 'placeholder'=>'Password')) }}
{{ Form::checkbox('remember_me','false',false,array('class'=>'input-block-level')) }}
{{ Form::submit('Login', array('class'=>'btn btn-large btn-primary btn-block'))}}
{{ Form::close() }}
@stop
CONTROLLER:
public function postSignin() {
if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password'),'active' => 1),Input::has('remember_me'))) {
return Redirect::to('users/dashboard')->with('message', 'You are now logged in!');
} else {
return Redirect::to('users/login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
请帮我解决这个问题,此功能不会记住用户。 如果您有更好的代码,那么请告诉我。 谢谢。
答案 0 :(得分:0)
如果您想记住用户传递第三个参数true
if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
// The user is being remembered...
}
您的代码:
public function postSignin() {
$rememberMe = false;
if(Input::has('remember_me')) {
$rememberMe = true;
}
if (Auth::attempt(array('email'=> Input::get('email'), 'password'=> Input::get('password') ), $rememberMe )) {
return Redirect::to('users/dashboard')->with('message', 'You are now logged in!');
} else {
return Redirect::to('users/login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}