2014-04-05 4 views
0

여러 번했는데이 문제가 발생하지 않았습니다. AuthComponent가 사용자 ID를 반환하지 않습니다.

$this->Auth->user()

usernamepassword 필드

$this->Auth->user('id') 복귀 널 배열을 반환한다.

누구나? 의 AppController에서

편집

AuthComponent 정의 :

<?php 

class User extends AppModel { 

public $validate = array(
    '_password' => array(
     'equaltofield' => array(
      'rule' => array('equaltofield', 'password'), 
      'message' => 'Require the same value to password.', 
     ) 
    ) 
); 

public function beforeValidate ($options = array()) { 
    $this->data[$this->alias]['password'] = AuthComponent :: password($this->data[$this->alias]['password']); 
    $this->data[$this->alias]['_password'] = AuthComponent :: password($this->data[$this->alias]['_password']); 
} 

function equaltofield($check,$otherfield) { 
    $fname = ''; 
    foreach ($check as $key => $value){ 
     $fname = $key; 
     break; 
    } 
    return $this->data[$this->name][$otherfield] === $this->data[$this->name][$fname]; 
} 

} 

?> 

UsersControl : 2

사용자 모델

public $components = array(
    'Session', 
    'Cookie', 
    'Auth' => array(
     'authorize' => 'Controller', 
     'loginError' => 'Invalid account specified', 
     'authError' => 'No Permission', 
     'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 
    ), 
); 

편집 LER 로그인/로그 아웃 기능 :

public function login() { 
    if($this->request->is('post')) { 
     if($this->Auth->login($this->request->data)) { 
      if($this->Auth->user('role' == 'administrator')) { 
       return $this->redirect(array('controller' => 'brands', 'action' => 'index')); 
      } 
      else { 
       return $this->redirect(array('controller' => 'visits', 'action' => 'index')); 
      } 
     } 
     else { 
      $this->Session->setFlash('Login incorrect');  
     } 
    } 
} 

public function logout() { 
    $this->Auth->logout(); 
    return $this->redirect(array('action' => 'login')); 
} 
+0

된 직후해야 $this->Auth->login();

에서 $this->request->data를 제거

Action (작업) 로그인에? –

+0

Auth 구성 요소 설정으로 내 질문을 업데이트했습니다. –

+0

인증 설정이 양호합니다. 캐싱 문제 일 수 있습니다 .... 캐시 폴더를 비우십시오. 작동하지 않으면 Users.php, UsersController.php ...와 같은 많은 정보로 질문을 업데이트하십시오. –

답변

1

문제는 당신이 당신의 인증 구성 설정을 정의하는 방법

public function login() { 
    if($this->request->is('post')) { 
     if($this->Auth->login()) { 
      if($this->Auth->user('role' == 'administrator')) { 
       return $this->redirect(array('controller' => 'brands', 'action' => 'index')); 
      } 
      else { 
       return $this->redirect(array('controller' => 'visits', 'action' => 'index')); 
      } 
     } 
     else { 
      $this->Session->setFlash('Login incorrect');  
     } 
    } 
} 
+0

Spot on! 고맙습니다! –