내 컨트롤러에는 경로가 작동하는 사용자 로그가 있었지만 메서드 자체가 매우 길어서 사용자가 금지되고 IP 로깅 등의 여러 문제가 발생할 수 있습니다. 이 방법을 중단하여 좀 더 관리하기 쉬워서 이것이 가능한지 궁금 해서요? 'postLogin()가'경로입니다 여기 는 3 가지 방법은 다음과 같습니다다른 '도우미'메서드를 호출하는 Laravel 컨트롤러 메서드
public function postLogin()
{
$validator = Validator::make(Input::all(), array(
'login-username' => 'required',
'login-password' => 'required'
));
if($validator->fails())
return Redirect::back()->withErrors($validator)->withInput();
else
{
$user_attempt = Input::get('login-username');
$pass_attempt = Input::get('login-password');
$auth = Auth::attempt(array(
'username' => $user_attempt,
'password' => $pass_attempt
), true);
if($auth)
$this->handleAuth();
else
return Redirect::route('home')->with('fail', 'Incorrect username or password, username: ' . $user_attempt . ' pass: ' . $pass_attempt);
}
}
private function handleAuth()
{
$username = Auth::user()->username;
$banned_info = UserBans::getBanned($username);
$stored_ip = Auth::user()->ip_address;
$current_ip = User::getIp();
if($stored_ip != $current_ip)
User::updateIp(Auth::user(), $current_ip);
if(is_null($banned_info))
return Redirect::intended('/');
else
$this->handleBan($banned_info, $current_ip);
}
private function handleBan($banned_info, $current_ip)
{
if(UserBans::isBanned($banned_info['ban_end']))
{
$message = "This account is currently banned until: " . $banned_info['ban_end'] . " Reason: " . $banned_info['reason'];
if($banned_info['ip_address'] != $current_ip)
{
$banned_model = UserBans::getBannedModel($banned_info['id']);
User::updateIP($banned_model, $current_ip);
}
Auth::logout();
return Redirect::route('home')->with('fail', $message);
}
else
{
UserBans::destroy($banned_info['id']);
return Redirect::intended('/');
}
}
내가 찾는거야 문제는 메인 컨트롤러 방법은 그러나 도우미 메서드가 시도 문제없이 헬퍼 메소드를 호출하는 것입니다 때이 방법 그러나,
사용자가 금지하고 올바른 자격 증명이되지 않은 경우가 발생if(is_null($banned_info))
return Redirect::intended('/');
, 일반적으로는 홈 페이지로 리디렉션 것입니다 그리고 당신은 로그인해야합니다 : handleAuth()에서 예를 들어 경로로 리디렉션 'postLogin'경로 URL에 빈 페이지가 남았습니다. .
Route::group(array('before' => 'guest'), function()
{
Route::group(array('before' => 'csrf'), function()
{
Route::post('/user/login', array('uses' => '[email protected]', 'as' => 'postLogin'));
});
});
이 laravel 라우팅/컨트롤러와 함께 할이 가능 : 당신이 집에 당신이 페이지를 새로 고침하고 로그인하는 경우 여기에 해당 경로입니까? 그렇지 않은 경우이 상황을 처리하는 방법에 대한 권장 사항을 제공 할 수 있습니까?