Я пытаюсь войти в приложение CakePHP 2.0
, но всегда получаю ошибку входа. В официальном documentation и tutorial я прочитал, как хэширования паролей, но я все еще получаю ошибку входа в систему, вот как я это сделал:Хеширование паролей и 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');
}
}
}
В представлении я это:
// 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, я получаю: Fatal error: вызов функции-члена sessionFlash() для не-объекта в /public_html/site.com/app/View/Layouts/default.ctp | 3) Я посмотрю на это! спасибо – vitto
(2) И убедитесь, что вы установили помощник 'Layout' в массив' $ helpers' на вашем контроллере или AppController. 'public $ helpers = array (/ * others * /, 'Layout',/* others * /)'; – colares
Возможно, вы говорите: ' Php echo $ this-> Session-> flash(); echo $ this-> Session-> flash ('auth'); ?> 'это работает, я использую его для получения ошибки – vitto