如何在laravel 4上执行自定义auth::try消息


How to do custom auth::attempt message on laravel 4

我需要帮助,所以当他登录时会出现不同的错误——例如,这是我的代码,我仍然不知道如何返回不同的错误。

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']);

EDIT1

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']);
    }

EDIT2

我的答案

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'
        ]);
}