0
내 CakePHP 2.0
응용 프로그램에 로그인하려고하는데 로그인 오류가 발생합니다.암호 해시 및 AuthComponent
// Users Model
public function beforeSave ($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}
// Users Controller
public $components = array ('Acl', 'Session',
'Auth' => array (
'authenticate' => array (
// login e logout sono di default i seguenti controller e views
// 'loginRedirect' => array ('controller' => 'users', 'action' => 'login'),
// 'logoutRedirect' => array ('controller' => 'users', 'action' => 'logout'),
'Form' => array (
'fields' => array (
// il valore default
'username' => 'email'
),
'scope' => array (
'User.active' => 1
)
)
),
'authError' => 'Login error message I get'
));
public function login() {
if ($this->request->is('post')) { // if the request came from post data and not via http (useful for security)
// the password is hashed in User Model in beforeSave method as read on documentation
// debug ($this->data);
if ($this->Auth->login()) {
$id = $this->Auth->user('id');
return $this->redirect(array('controller'=>'users', 'action'=>$id, $this->Auth->user('username')));
} else {
$this->Session->setFlash('Login error message', 'default', array(), 'auth');
}
}
}
: 공식 documentation 내가 암호를 해시,하지만 난 여전히 로그인 오류를 얻는 방법을 읽은 tutorial에서 은, 여기에 내가 그것을 어떻게입니다 내가 데이터를 디버깅하려고하면
// the view login.ctp
echo $this->Form->text('User.email', array('id'=>'email', 'value'=>'[email protected]'));
echo $this->Form->password('User.password', array('id'=>'password', 'value'=>'password'));
나는이 얻을 :
// in the controller
debug($this->data);
// in the view
Array
(
[User] => Array
(
[email] => [email protected]
[password] => thepass // not hashed
)
)
난 항상 Login error message
를 얻을 수 있기 때문에이 로그인 할 수 없습니다. 어떻게 해결할 수 있습니까?
감사합니다. 1) 질문에서 오류를 업데이트했습니다. | 2) sessionFlash를 인쇄하려고하면 다음과 같은 오류가 발생합니다. 치명적 오류 : /public_html/site.com/app/View/Layouts/default.ctp의 비 객체에서 sessionFlash() 멤버 함수를 호출합니다. 3) 나는 이것을 보게 될 것이다! thanks – vitto
(2) 컨트롤러 나 AppController에서'$ helpers' 배열의 도우미'Layout'을 설정했는지 확인하십시오. 'public $ helpers = array (/ * others * /, 'Layout',/* others * /)'; – colares
어쩌면 당신이 말하는거야 :''? php echo $ this-> Session-> flash(); echo $ this-> Session-> flash ('auth'); ?>'이 함수는 에러를 내기 위해 사용한다. – vitto