2014-01-15 49 views
0

我从4.0升级Laravel到4.1后,用户身份验证失效。Laravel 4:用户未入住登录

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

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

例如,在我的HomeController指数法,我强迫登录像这样:

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

我呼应的布局$用户和它完美地显示用户信息。

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

编辑

我使用倾诉3.1.0用户认证和这里是do_login()函数。我已经做了&立即转储在第一个'如果'以确认Confide :: logAttempt返回true。

我也完全隐藏了整个模块,并简单地完成了'echo Auth :: 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('[email protected]') 
         ->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

分享你的登录代码,其中用户登录第一个地方 – Anam

+0

我有同样的问题,它原来是一个问题与Barryvdh调试栏 - 如果您使用此调试栏,然后升级到最新的开发主人它应该解决问题 – glendaviesnz

+0

谢谢glendaviesnz,但我没有使用该调试栏。全球搜索我的代码库只是为了绝对肯定。 – brianrhea

回答

0

我很抱歉地说,我所做的就是创造一个干净的安装Laravel的,然后复制我的控制器/模型/浏览/路线等到新的安装和它完美的工作。

我确定必须有一些潜在的原因,为什么它退出工作,我希望我能通过追踪问题拯救任何其他人。但是,在尝试了许多不同的建议之后,这是最终修复它的原因。