CakePHP 2.0 - 能够注册,但无法登录

时间:2014-06-02 17:36:49

标签: cakephp

Im CakePHP新手,如果有人问我搜索它但找不到问题,请道歉。我的代码有问题。它在我注册新用户时效果很好,当我尝试登录时遇到问题并且出现错误"无效的用户名或密码');请帮忙

public function login() {

if ($this->request->is('post')) {
        if ((!empty($this->request->data['User']) && $this->Auth->login())) {
            $this->Session->setFlash(__('Welcome, '. $this->Auth->user('username')));
            $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Session->setFlash(__('Invalid username or password'));
        }
    } 
}

// ******* 登录CTP ************

<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>

<fieldset>
    <legend><?php echo __('Please enter your username and password'); ?></legend>
    <?php echo $this->Form->input('username');
    echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>

// *******************保存之前********************* ****

 public function beforeSave($options = array()) {
    // hash our password
    if (isset($this->data[$this->alias]['password'])) {
        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
    }

    // if we get a new password, hash it
    if (isset($this->data[$this->alias]['password_update']) && !empty($this->data[$this->alias]['password_update'])) {
        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password_update']);
    }

    // fallback to our parent
    return parent::beforeSave($options);
}

0 个答案:

没有答案