Laravel 4:用户没有登录

时间:2014-01-15 22:59:10

标签: laravel laravel-4

我将Laravel从4.0升级到4.1后,我的用户身份验证失败了。

我按照文档提供的升级指南。

现在,当我登录时,似乎只能持续一个请求。

例如,在我的HomeController索引方法中,我强制登录如下:

Auth::login(User::find(1), true);
$user = Auth::user();
return View::make('layout', array('user' => $user));

我在布局上回显了$ user,它完美地显示了用户信息。

但是,如果我通过简单地删除使用Auth登录然后刷新页面的第一行来修改控制器,那么它就是空白。

修改

我使用Confide 3.1.0进行用户身份验证,这里是do_login()函数。我做了一个死&立即转储到第一个'if'内,以确认Confide :: logAttempt返回true。

我还完全隐藏了整个块并简单地完成了一个'echo Auth :: user()',它确实为我刚刚登录的用户返回了User模型。

public function do_login()
{
    $input = array(
        'email'    => Input::get( 'email' ), // May be the username too
        'username' => Input::get( 'email' ), // so we have to pass both
        'password' => Input::get( 'password' ),
        'remember' => Input::get( 'remember' ),
    );
    // If you wish to only allow login from confirmed users, call logAttempt
    // with the second parameter as true.
    // logAttempt will check if the 'email' perhaps is the username.
    // Get the value from the config file instead of changing the controller

    if ( Confide::logAttempt( $input, Config::get('confide::signup_confirm') ) )
    {
        // Redirect the user to the URL they were trying to access before
        // caught by the authentication filter IE Redirect::guest('user/login').
        // Otherwise fallback to '/'
        // Fix pull #145
        return Redirect::intended('/'); // change it to '/admin', '/dashboard' or something
    }
    else
    {
        $user = new User;

        // Check if there was too many login attempts
        if( Confide::isThrottled( $input ) )
        {
            $err_msg = Lang::get('confide::confide.alerts.too_many_attempts');
        }
        elseif( $user->checkUserExists( $input ) and ! $user->isConfirmed( $input ) )
        {
            $err_msg = Lang::get('confide::confide.alerts.not_confirmed');
        }
        else
        {
            $err_msg = Lang::get('confide::confide.alerts.wrong_credentials');
        }

                    return Redirect::action('UserController@login')
                        ->withInput(Input::except('password'))
            ->with( 'error', $err_msg );
    }

}

这是logAttempt()函数

public function logAttempt( $credentials, $confirmed_only = false, $identity_columns = array() )
{
    // If identity columns is not provided, use all columns of credentials
    // except password and remember.

    if(empty($identity_columns))
    {
        $identity_columns = array_diff(
            array_keys($credentials),
            array('password','remember')
        );
    }

    // Check for throttle limit then log-in
    if(! $this->reachedThrottleLimit( $credentials ) )
    {
        $user = $this->repo->getUserByIdentity($credentials, $identity_columns);

        if(
            $user &&
            ($user->confirmed || ! $confirmed_only ) &&
            $this->app['hash']->check(
                $credentials['password'],
                $user->password
            )
        )
        {
            $remember = isset($credentials['remember']) ? $credentials['remember'] : false;

            $this->app['auth']->login( $user, $remember );
            return true;
        }
    }

    $this->throttleCount( $credentials );

    return false;
}

1 个答案:

答案 0 :(得分:0)

我很遗憾地说,我所做的就是创建一个干净的Laravel安装,然后将我的控制器/模型/视图/路由等复制到新安装中,它运行良好。

我确信必须有一些潜在的原因让它退出工作,我希望通过追查问题我可以挽救其他任何人。然而,在尝试了许多不同的建议后,最终解决了这个问题。