2014-02-15 120 views
0
public function login() { 

     //if already logged-in, redirect 
     if($this->Session->check('Auth.User')){ 
      $this->redirect(array('controller'=>'pages','action' => 'index'));  
     } 

     // if we get the post information, try to authenticate 
     if ($this->request->is('post')) { 
      if ($this->Auth->login()) { 
       $status = $this->Auth->user['status']; 
       if($status != 0){ 
        $this->Session->setFlash(__('Welcome, '. $this->Auth->user('username'))); 
        $this->redirect(array('controller'=>'pages','action' => 'index')); 
       }else{ 
        $this->Session->setFlash(__('The user is not active')); 
       } 
      } else { 
       $this->Session->setFlash(__('Invalid username or password')); 
      } 
     } 
    } 

爲什麼我用這個函數進行登錄。在我第一次登錄狀態1時,系統報告用戶沒有激活,但我第二次登錄狀態爲1好。Cake php auth登錄回覆

+0

你的問題是什麼? –

回答

2

變化

$status = $this->Auth->user['status']; 

$status = $this->Auth->user('status'); 

userAuthComponent

的功能。如果你想只記錄用戶status = 1,你也可以嘗試使用scope

e xample:

public $components = array(
'Auth' => array(
    'authenticate' => array(
     'Form' => array(
      'scope' => array('status' => '1') 
     ), 

    ) 
), 

);