好吧,我的登录功能返回TRUE,我已连接。
但是当我检查变量$ this-> Auth->用户,结果为空。
为什么?
// AppController.php
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'E-Mail',
'password' => 'MPDweb'
)
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
)
);
// login.ctp
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User', array('action' => 'login')); ?>
<?php echo $this->Form->input('E-Mail', array('class' => 'form-control', 'autofocus' => 'autofocus')); ?>
<br />
<?php echo $this->Form->input('MPDweb', array('class' => 'form-control')); ?>
<br />
<?php echo $this->Form->button('Login', array('class' => 'btn btn-primary')); ?>
<?php echo $this->Form->end(); ?>
// UsersController.php
public function login(){
// var_dump($this->request->data);
if ($this->request->is('post')) {
if($this->Auth->login()){
$this->Session->setFlash('Vous êtes bien connecter');
var_dump($this->Auth->login());
} else {
$this->Session->setFlash('Inentifiant ou mot de passe incorrect');
}
// debug($this->Auth->login());
}
}
// user.php的
App::uses('AppModel', 'Model');
//App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
class User extends AppModel {
public $useTable = 'prospect';
public $primaryKey = 'code_client';
}
注意:目前,我没有使用“hash”
方法对密码进行编码