Я новичок в CakePHP. Я пробую руководство по кулинарной книге Cake простая аутентификация с CakePHP 2.4.1.
Я всегда получаю сообщение "Неверное имя пользователя или пароль, попробуйте еще раз", хотя я ввел правильное имя пользователя и пароль.
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
Согласно API AuthComponent, если параметр Auth->login()
пуст или нет указано, запрос будет использоваться для идентификации пользователя. Выходные данные отладочного запроса показывают
SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`role`, `User`.`created`, `User`.`modified`
FROM `cake_dvdcatalog`.`users` AS `User` WHERE `User`.`username` = 'admin' LIMIT 1
Вот моя модель пользователя:
// app/Model/User.php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
)
),
'role' => array(
'valid' => array(
'rule' => array('inList', array('admin', 'author')),
'message' => 'Please enter a valid role',
'allowEmpty' => false
)
)
);
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;
}
}