我需要帮助,所以当他登录时会出现不同的错误,例如,这是我的代码,直到不知道如何返回不同的错误。
public function postLogin()
{
$user = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1
);
if (Auth::attempt($user, (Input::get('remember') == 'on') ? true : false)) {
return Redirect::route('home');
}
// authentication failure! lets go back to the login page
return Redirect::route('login')
->with('flash', ['message' => '<strong>Error!</strong> Account is not registered.',
'type' => 'danger']);
}
我的问题是如何添加这两个自定义重定向
如果用户具有正确的用户名/密码,但是active = 0
,它将返回
return Redirect::route('login')
->with('flash', ['message' => '<strong>Error!</strong> Account is not verified.',
'type' => 'danger']);
并且如果用户输入了错误的用户名/密码,它将像这样返回
return Redirect::route('login')
->with('flash', ['message' => '<strong>Error!</strong> Wrong password.',
'type' => 'danger']);
编辑1
public function postLogin()
{
$user = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
if(Auth::attempt($user, (Input::get('remember') == 'on') ? true : false)) {
if(Auth::user()->active == 1) {
if(Auth::user()->isBanned == 0 ) {
return Redirect::route('home');
}
Auth::logout();
$message = '<strong>Error!</strong> Your account was banned for misconduct.';
}
Auth::logout();
$message = '<strong>Error!</strong> Account is not verified.';
} else {
$message = '<strong>Error!</strong> Wrong password.';
}
// authentication failure! lets go back to the login page
return Redirect::route('login')
->with('flash', ['message' => $message,
'type' => 'danger']);
}
编辑2
我的答案
public function postLogin()
{
$user = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
if(Auth::attempt($user, (Input::get('remember') == 'on') ? true : false)) {
if(Auth::user()->active == 1 && Auth::user()->isBanned == 0) {
return Redirect::route('home');
}
if(Auth::user()->active == 0) {
$message = '<strong>Error!</strong> Account is not verified.';
} else if (Auth::user()->isBanned == 1) {
$message = '<strong>Error!</strong> Your account was banned for misconduct.';
}
Auth::logout();
} else {
$message = '<strong>Error!</strong> Wrong password.';
}
// authentication failure! lets go back to the login page
return Redirect::route('login')
->with('flash', ['message' => $message,
'type' => 'danger']);
}
请尝试以下方法。
public function postLogin()
{
$user = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($user, Input::has('remember'))) {
if (Auth::user()->active == 1 && Auth::user()->isBanned != 0) {
return Redirect::route('home');
}
$message = '<strong>Error!</strong> Account is not verified.';
if (Auth::user()->isBanned == 0) {
$message = '<strong>Error!</strong> Your account was banned for misconduct.';
}
Auth::logout();
} else {
$message = '<strong>Error!</strong> Wrong password.';
}
return Redirect::route('login')
->with('flash', [
'message' => $message,
'type' => 'danger'
]);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句