验证cookie插件记住我的功能问题

时间:2015-09-15 18:42:06

标签: php cakephp cookies

我在我的项目中使用authenticate cakephp插件,我想利用插件的cookieauthenticate类,问题是插件没有读取cookie来验证它是否已经超过了到期日,因为当我改变时即使我的cookie的日期尚未到期,我的系统的日期也会被用户注销。 当我验证我发现它时,它只需要 CakePHP cookie而不是我创建的cookie。 这是我使用的代码: 在appcontroller中,我的组件包含此代码

public $components = array('Auth' => array(
            'authorize' => array(
                'Actions' => array('actionPath' => 'controllers')
            ),
            'authenticate'=> array(
               'Authenticate.Cookie' => array(
                    'fields' => array(
                        'username' => 'login',
                        'password' => 'password'
                    ),
                    'userModel' => 'User',
                    'scope' => array('User.active' => 1)
            ),
               'Authenticate.MultiColumn' => array(
                    'fields' => array(
                        'username' => 'login',
                        'password' => 'password'
                    ),
                    'columns' => array('login', 'email'),
                    'userModel' => 'User',
                    'scope' => array('User.active' => 1)
                )
            ),
            'unauthorizedRedirect' => array(
                'controller' => 'users',
                'action' => 'home',
                'prefix' => false)
        ),'Session','Cookie')

在我的用户控制器中我得到了这段代码:

public function login() {
        $this->layout='login';

            if ($this->Auth->loggedIn() || $this->Auth->login()) {
                $this->_setCookie();
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Session->setFlash(__('Your username or password was incorrect.'));

    }

    protected function _setCookie() {
        if (!$this->request->data('User.remember_me')) {
            return false;
        }

        $data = array(
            'username' => $this->request->data('User.login'),
            'password' => $this->request->data('User.password')
        );
        $this->Cookie->write('User', $data, true, '+1 week');
        return true;
    }

    public function logout() {

        $this->redirect($this->Auth->logout());
    }
    public function beforeFilter() {
    parent::beforeFilter();
    $this->Cookie->type('rijndael');
}

我正在使用cakephp 2.6。

提前致谢

0 个答案:

没有答案