2014-03-28 66 views
0

我在Laravel使用Sentry更新用戶信息時遇到了問題。用Laravel和Sentry更新用戶信息

我在我的控制器有這樣的:

public function update() 
{ 
    try{ 
     $user = $this->sentry->getUser(); 

     $user->username  = $this->input->get('username'); 
     $user->first_name = $this->input->get('first_name'); 
     $user->last_name = $this->input->get('last_name'); 
     $user->email  = $this->input->get('email'); 
     $user->description = $this->input->get('description'); 

     if (!$this->hash->check($this->input->get('password'), $user->password)) 
     { 
      $user->password = $user->password; 
     } else { 
      $user->password = $this->input->get('password'); 
     } 

     if($user->save()) 
     { 
      return $this->redirect->to('admin'); 
     } else { 
      return $this->redirect->to('admin/'.$user->username.'/'); 
     } 
    } 
    catch (\Exception $e) 
    { 
     return $this->redirect->to('user/'.$user->username.'/profile/edit')->withErrors(array('login'=> $e->getMessage())); 
    } 
} 

將提交表單時進行處理。但是,如果我不在輸入字段中填寫密碼,而是更新用戶信息的其他內容並提交表單。它還需要'空'密碼字段,並使其與完全不同,因此我不能再使用原始密碼登錄。

我知道hash->check部分有問題,但是什麼?我不知道。幫助將不勝感激。

編輯: 我試圖檢查,如果密碼字段是否填寫,如果它沒有填寫,保持密碼,因爲它,如果它填寫,檢查它是否不同於當前的密碼,如果它的不同,改變它,否則離開它,因爲它是

回答

0

變化

if (!$this->hash->check($this->input->get('password'), $user->password)) 
    { 
     $user->password = $user->password; 
    } else { 
     $user->password = $this->input->get('password'); 
    } 

if ($this->input->get('password')) 
    { 
     $user->password = $this->input->get('password'); 
    }