2013-07-29 94 views
1

我的驗證組件在過去一年中一直正常運行。我大約兩個小時前登錄了我的網站,並做了一個小改動。我在這兩個小時裏下了車,大約半小時前我回來了,但我一直無法登錄到我的網站。錯誤消息說用戶名/密碼組合不正確。我想不知道數值在我的數據庫中發生了變化,或者我的瀏覽器自動保存了一箇舊密碼,所以爲了確保我的數據庫中的密碼更新了適當的md5哈希值,我在瀏覽器中再次嘗試了它。它仍然沒有工作。CakePHP Auth登錄已停止工作

我清空我的緩存(這是我經常以任何方式做的事情),因爲我建議從this post這樣做,但這也不起作用(也沒有幫助該問題的海報)。該人的解決方案添加了一些視圖文件,打破了數據庫連接不適用於我,因爲我沒有更改任何視圖文件。我也沒有改變用戶模型或應用程序控制器。在我之前的時間裏,我改變了唯一的一件事,那就是我編輯了UsersController的online()動作。我已經改變了它。事實上,我進入了我的站點備份工具,並將所有控制器和模型文件恢復到最近的備份,這是2天前所有工作都正常的時候。仍然沒有影響。

我無法登錄我已註冊的任何帳戶。我甚至在數據庫中取消了其中一個密碼並嘗試使用該帳戶登錄,但這也不起作用。

AppController的

//I HAVE NOT CHANGED THIS IN SEVERAL MONTHS 

public $helpers = array('Form', 'Html', 'Custom', 'Time', 'Js', 'Cache'); 
public $components = array('CustomPage', 'Session', 'CustomUser', 
    'Auth' => array(
     'autoRedirect' => false, 
     'loginAction' => array('controller' => 'users', 'action' => 'login', 'prefix' => false, 'admin' => false, 'moderate' => false), 
     'loginRedirect' => array('prefix' => false, 'admin' => false, 'moderate' => false, 'controller' => 'account', 'action' => 'index'), 
     'logoutRedirect' => array('controller' => 'index', 'prefix' => false, 'admin' => false, 'moderate' => false), 
     'authError' => "You can't access that page", 
     'authorize' => array('Controller') 
    ) 
); // components 

public function isAuthorized($user) { 
    return true; 
} 

UsersController

// DID NOT CHANGE FOLLOWING ACTION 

public function login() { 
    if ($this->Session->read('Auth.User')) { 
     $this->Session->setFlash('You are already logged in'); 
     $this->redirect(array('controller' => 'account', 'action' => 'index')); 
    } 

    $this->layout = "simple"; 
    $this->set('title_for_layout', 'Login'); 

    if ($this->request->is('post')) { 
     $this->User->UsersOnline->deleteAll(array('UsersOnline.session' => $this->viewVars['session_session']), false); 

     if ($this->Auth->login()) { // check user is logged in 
      $this->User->id = $this->Auth->user('id'); 
      $this->User->saveField('last_login', date(Configure::read('Site.date_format'))); // save login time 
      $this->redirect($this->Auth->redirect()); // redirect to default place 
     } else { 
      $this->Session->setFlash('Your username/password combination was incorrect'); 
     } 
    } 
} // end login 


// THE FOLLOWING ACTION WAS THE ONLY THING 
// THAT WAS CHANGED BUT IT IS NOW BACK TO ORIGINAL VERSION 

public function online() { 
    $page_id = $this->viewVars['page_id']; 
    $link = $this->viewVars['link']; 

    // CONTAIN 
    $this->User->UsersOnline->contain(array(
     'User' => array(
      'fields' => array(
       'User.username', 'User.online' 
      ), 
      'Avatar' => array(
       'fields' => array(
        'Avatar.file' 
       ) 
      ) 
     ) 
    )); 

    if($page_id){ 
     $this->set('users', $this->paginate($this->User->UsersOnline, array('UsersOnline.page_id' => $page_id))); 
     $this->set('title_for_layout', 'Fans Online'); 
    } 
    else{ 
     $this->set('title_for_layout', 'Users Online'); 
     $this->set('users', $this->paginate($this->User->UsersOnline)); 
     $this->layout = "default"; 
    }  
} // end online action 

我的用戶模型使用標準的 「用戶名」 和 「密碼」 列對用戶進行驗證。

我已經添加下面的代碼到我的UserController中的login()動作並打印出正確的結果......

$password = md5($this->request->data['User']['password']); 

print_r(
    $this->User->find('first', 
     array(
      'User.username' => $this->request->data['User']['username'], 
      'User.password' => $password 
     ) 
    ) 
); 

再次,我已經恢復了所有的控制器和模型文件,以他們的狀態2天所以我真的不知道可能是什麼原因造成的。

編輯1:現在爲了安全起見,我將所有視圖文件恢復爲本週末的最新備份版本。這並沒有解決這個問題。

編輯2:如果我調試$this->Auth->login,結果爲空。如果沒有什麼變化,爲什麼這個會突然變空?

編輯3:我UsersController寄存器()動作正確創建新的用戶並自動登錄用戶

UsersController

public function register() { 
    if($this->Session->read('Auth.User')) { 
     $this->Session->setFlash('You are already registered'); 
     $this->redirect(array('controller' => 'account', 'action' => 'index')); 
    } 

    $this->layout = "simple"; 
    $this->set('title_for_layout', 'Register'); 
    if ($this->request->is('post')) { 
      $this->User->create(); 

      if ($this->User->save($this->request->data)) { 
       $id = $this->User->id; 
       $this->request->data['User'] = array_merge($this->request->data['User'], array('id' => $id)); 

       if($this->Auth->login($this->request->data['User'])){ 
        $this->Session->setFlash(__('Your account has successfully been created and you have logged in')); 
        $this->redirect(array('controller' => 'account', 'action' => 'index')); 
       } // end if account created and successful log in 
       else{ 
        $this->Session->setFlash(__('Your account has successfully been created but you cannot log in')); 
       } // end else if account created but not logged in 
      } else { 
       $this->Session->setFlash(__('Your account could not be created. Please, try again.')); 
     } // end else if account cannot be created 
    } // end if method is post 
} // end register 
+0

刪除所有文件你有權限的控制(如ACL)設置?也許您正在登錄,但沒有訪問操作的權限,並且錯誤消息與實際問題不符? – Nunser

+0

不..我一直記錄下來,它正在將我引導到用戶儀表板的帳戶控制器。直到幾個小時前,這一切都運行良好。我想不出任何可能導致此問題的變化,即使如此,我已經恢復了所有的變更。我只在兩個獨立的瀏覽器(firefox和chrome)上在一臺設備(電話)上進行了測試。我想知道問題出在我手機上。我以前從來沒有遇到過這個問題。當我在safari和firefox上下班回家時,我會在臺式計算機上進行測試。我已重新啓動手機 – bowlerae

+0

...不認爲設備或瀏覽器是問題。 – bowlerae

回答

0

嗯,我從來沒有想出INITIAL什麼問題是,但現在我發現恢復所有更改的控制器,模型和視圖文件似乎解決了這個問題。這仍然困擾我,我不知道最初的問題是什麼。

但是,我發現在將我的數據庫中的所有密碼更新爲其對應的md5哈希值後,這給了我持續的問題。我想Cake不會使用我認爲密碼不匹配的md5。所以,即使在恢復所有更改的文件之後,密碼也都變得不正確。

如果我弄清楚原來的問題是什麼,我會更新。

+0

你的意思Cake不使用md5? – XuDing

0

它可以幫助從tmp/cachetmp/models