新しい登録とログインページを作成しようとしています。私はログインに問題があります。CakePHP 2.0:ログインフォームが動作しない
1)私はそれが成功したハッシュされ、DBに保存されたユーザ名とパスワードを登録した後、以下のコードを見つけてください:(すべてはケーキの規則に従っている)
User.php:
<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
......
public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
}
?>
UsersController.php:
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->saveAll($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array('controller' => 'Posts','action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}
public function login() {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'), 'default', array(), 'auth');
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
login.ctp:
<fieldset>
<?php echo $this->Session->flash('auth'); ?>
</fieldset>
<?php echo $this->Form->create('Users');?>
<fieldset>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login'));?>
デバッグ:(デバッグ(の$ this - >データ);)
のAppControllerから:
Array
(
[Users] => Array
(
[username] => vinodronold
[password] => vinodronold
)
)
がUserControllerから:
Array
(
[Users] => Array
(
[username] => vinodronold
[password] => vinodronold
)
)
問題:
私がアクセスするたび/ユーザー/ログインURL「無効なユーザー名またはパスワード、再試行」メッセージが表示されます。
また、正しいユーザー名とパスワードを入力してもログインできません。
助けてください。
ありがとうございます!!!近いそれを見て
は
すべて正しく表示されます。パスワードが暗号化されたデータベースに保存されていることを確認しましたか? –
はい。パスワードはハッシュ後に保存されます。 $ this-> data [$ this-> alias] ['password'] = AuthComponent :: password($ this-> data [$ this-> alias] ['password']);何かする設定がある、私は何かが不足している.. –