0

Cake 没有保存 cookie,至少我看不到,当我重新访问该页面时,我没有自动登录。我实际上想实现“记住我的功能”。我正在使用这个组件 https://github .com/ceeram/Authenticate/wiki/Set-Cookie

这是我的代码

登录.ctp

echo $this->form->create();

echo $this->form->input('email');
echo $this->form->input('password');

 <?php echo $this->Form->checkbox('remember_me', array('hiddenField' => false,'name' =>   'remember_me'));?>
 echo $this->form->end('submit');
 ?>

用户控制器

<?php
  class UsersController extends AppController {

 public $components = array('Cookie');

 public function beforeFilter() {
    parent::beforeFilter();

    $this->Cookie->type('rijndael');

    $this->Security->requireSecure('login');// for security
    $this->Auth->authenticate = array(
        'Authenticate.MultiColumn' => array(
            'fields' => array(
                'username' => 'email',
                'password' => 'password'
            ),
            'columns' => array('email', 'mobileNo'),
            'userModel' => 'User',
        )
    );
}


public function index(){

}


public function login() {
    $this->layout='userdefault';
    if ($this->request->is('post')) {

        //$this->Auth->logout();
        $cookie = $this->Cookie->read('Auth.User');
        debug($cookie);
        if ($this->Auth->login()) {
            $this->_setCookie($this->Auth->user('id'));
            $this->redirect('/users/controlpanel');

        } else {
            $this->Session->setFlash('Incorrect Email/Password Combination');
        }
    }
}
  protected function _setCookie($id) {
    if (!$this->request->data('User.remember_me')) {
        return false;
    }
    $data = array(
        'username' => $this->request->data('User.email'),
        '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 controlpanel(){
    $this->layout='controlpaneldefault';

   }

  }
?>

并告诉我如何检查或调试 cookie 以检查我的 cookie 是否保存或是否无法调试然后告诉我如何设置 cookie 的名称以便我进入浏览器 cookie 并搜索 cookie有名字

4

1 回答 1

0

插入退出();调试后($cookie);用于检查 cookie 数据。

于 2013-06-16T18:04:31.043 回答