cakephp身份验证登录不工作
我有一个表用户,他的模型是cakephp身份验证登录不工作,php,cakephp,login,Php,Cakephp,Login,我有一个表用户,他的模型是 class User extends AppModel { public $useTable = 'user'; public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::pas
class User extends AppModel {
public $useTable = 'user';
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);}
return true;
}
在我的Userscontroller中
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__("Nom d'user ou mot de passe invalide, réessayer"));
}
}
}
在我的视图中login.ctp
我有
在AppController中
class AppController extends Controller {
public $components = array('Session',
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email'),
'password' => 'password',
'scope' => array('User.active' => 1)
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index')
)
);
public function beforeFilter() {
parent::beforeFilter();
}
public function isAuthorized($user) {
return true;
}
}
但是,当我想使用我的登录名和密码进行连接时,不会显示任何内容,也不会显示错误代码或将我重定向到您的型号中的我的帐户
public function beforeSave($options = array()) {
// hash our password
if (!$this->id) {
$passwordHasher = new SimplePasswordHasher();
$this->data['User']['password'] = $passwordHasher->hash($this->data['User']['password']);
}
return true;
}
在appcontroller中
public $components = array('Session',
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email',
'password' => 'password'),
'scope' => array('User.active' => 1)
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index')
)
);
public function beforeFilter() {
Security::setHash('sha1');
$this->Auth->allow('login','add', 'index');
}
在数据库密码中,只需输入VARCHAR(30)
在您的UserController中有这样的内容:
public function beforeFilter() {
parent::beforeFilter();
}
public $components = array('Session',
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email',
'password' => 'password'),
'scope' => array('User.active' => 1)
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index')
)
);
public function beforeFilter() {
Security::setHash('sha1');
$this->Auth->allow('login','add', 'index');
}
public function beforeFilter() {
parent::beforeFilter();
}