0

管理者/ユーザーのログインにCakePHP1.3の最新バージョンを使用しています。

Authを使用してログインしようとすると、最初の試行では情報が表示されませんSESSIONが、ページを再度更新すると、すべての情報がSessionに送信されるという非常に奇妙な問題に直面しています。

何かアイデア、なぜこれが起こったのですか?

コードはapp_controller.phpファイルからここにあります

function beforeFilter()
{   
    $this->Auth->autoRedirect = false;
    $this->Auth->fields = array('username' => 'email_address', 'password' => 'password');
    $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
    $this->Auth->userScope = array('User.status' => '1','User.paymentstatus' => '0');
    if($this->Auth->User())
    {
        if($this->Session->read('Auth.User.user_type') == 3) {
            $this->layout = 'admin';
            $this->Auth->loginRedirect = array('controller' => 'admins', 'action' => 'welcome');
        }
        else 
        {
            $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
        }
    }
}

function beforeRender(){
    $this->set('auth', $this->Auth->user());
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); // // HTTP/1.1
    header("Pragma: no-cache");
    header("Expires: Mon, 17 Dec 2007 00:00:00 GMT"); // Date in the past
}

早めの対応をお願いします。

ありがとう !

4

1 に答える 1

1
function beforeFilter(){   
  parent::beforeFilter();
  $this->Auth->autoRedirect = false;
  $this->Auth->fields = array('username' => 'email_address', 'password' => 'password');
  $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
  $this->Auth->userScope = array('User.status' => '1','User.paymentstatus' => '0');
  if($this->Auth->user() && $this->Auth->user('user_type') == 3)
        $this->layout = 'admin';
}
function login(){
  if($this->Auth->user()){
    if($this->Auth->user('user_type') == 3) {
        $this->redirect(array('controller' => 'admins', 'action' => 'welcome'));
    } else  {
        $this->redirect(array('controller' => 'pages', 'action' => 'display', 'home'));
    }
  }
 }

beforeRenderで認証を設定する必要はありませんが、ビューで認証にアクセスできます。$this->Session->read('Auth.User');

于 2011-08-09T09:44:35.207 に答える