我試圖在laravel 4.2的一個項目上工作,但現在,我想限制用戶的登錄嘗試次數。幾乎所有的解決方案都是laravel 5並且不熟悉與5.所以任何人有一個想法,請我需要你的幫助。謝謝。如何限制laravel 4用戶的登錄嘗試
$data = Input::all();
$rules = array(
'username' =>'required|',
'password' => 'required|min:6'
);
$validator = Validator::make($data, $rules);
if($validator->passes())
{
$user = array(
'username'=> Input::get('username'),
'password' => Input::get('password'),
'active'=>1,
);
if(Auth::attempt($user))
{
if((Auth::user()->isBuyer()))
{
return Redirect::route('customer')->with(['success' => 'Welcome <strong style="color:black">'.Auth::user()->name .'</strong>']);
}
elseif((Auth::user()->isSeller()))
{
return Redirect::route('seller')->with(['success' => 'Welcome <strong style="color:black">'.Auth::user()->name .'</strong>']);
}
else
{
return Redirect::route('dashboard')->with(['success' => 'Welcome <strong style="color:black">'.Auth::user()->name.' </strong>']);
}
}
return Redirect::back()
->with(array(
'error' => 'Your email and password combination is invalid or Verify your email first'
));
}
return Redirect::back()
->withInput()
->withErrors($validator);
}
是在
您可以爲您的用戶表添加一個'attempt'列。每增加一次,用戶嘗試登錄並檢查總嘗試次數 – Wistar