English 中文(简体)
我如何把“阿特”和“奥特”洛/登德”的职能混为“卡纳克人”的一种方法?
原标题:How do I blend the functions of isAuthorized and Auth->allow/deny into one method in CakePHP?

在我的设计中,行动等级为0至10(0为客人[未注明],10为行政)。 每个用户的级别为0-10。 如果您的级别或级别较高,你就可以采取行动,否则你就能够采取行动。 尼斯简而言之,这是我所需要的。

问题是,卡纳克民阵希望我以两个不同的概念对待行动。 我必须标注Austh->allow/deny,以确定下 au制度是否甚至与他们同时存在,然后我控制与他们接触。

为满足我的需要,可喜地工作...... 除此以外,我想要获得第0级的许可,只能是Austh->allow(然后完全无视我的“教化”方法)。 如果我否认所有页数,那么,在检查前,应排第0级的标识触发点,即使我通过授权,此人必须先登记。

是否有办法将这两个系统合并起来,还是取而代之的简单方法? 大部分的紧缩制度是巨大的,在我无需与我见面的情况下照顾我的工作......但是,这只是一个ward子,在我不注意到喜好或一些事情时会引发问题。

Thanks!

最佳回答

我认为,这样做的唯一途径是创建一个客座用户。 这是因为,Austh构成部分像你所解释的那样,先检查用户的存在,然后才到isAuthorized(>

你可以直接向本届会议写信。 这将告诉奥特部分,有人被gged住,因此,请打电话isAuthorized()。

<><>AppController>

public function beforeFilter() {
  // if no one is logged in, log in a guest
  if (!$this->Auth->user()) {
    $this->Session->write(AuthComponent::$sessionKey, array(
       User  => array(
         id  => 0
       )
    ));
  }
}

public function isAuthorized($user) {
  $authorized = false;
  if ($this->Auth->user( id ) == 0) {
    // public guest user access
  }
  // other logic
  return $authorized;
}

这样做的一个可能更好的途径是使用习惯认证标语,该标语基本上指Cake使用这一类别来帮助认证。 这种做法将逻辑分成一个单独的类别,使测试更加容易,甚至变得不可行。

app/Controller/Component/Auth/GuestAuthenticate.php

App::uses( BaseAuthenticate ,  Controller/Component/Auth );

class GuestAuthenticate extends BaseAuthenticate {
    public function authenticate(CakeRequest $request, CakeResponse $response) {
        // no real authentication logic, just return a guest user
        return array( User  => array( id  => 0));
    }
}

<><>AppController>

public $components = array(
   Auth  => array(
     authenticate  => array(
       Form ,
       Guest  // tell Cake to try Form authentication then Guest authentication
    )
  )
);

public function beforeFilter() {
  if (!$this->Auth->user()) {
    // no user? log in a guest (this will fail form authentication
    // then try guest authentication)
    $this->Auth->login();
  }
}

public function isAuthorized($user) {
  $authorized = false;
  if ($this->Auth->user( id ) == 0) {
    // public guest user access
  }
  // other logic
  return $authorized;
}

http://book.cakephp。

问题回答

也许这个问题已经令人满意地处理,但我有解决办法。

In my AppController I have the following:

    public function isAuthorized($user = null) {
        if (in_array($this->action, $this->Auth->allowedActions)) {
            return true;
        }
        return false;
    }

As you ve found, if you don t explicitly authorize actions, they are denied to authenticated users, even if they are allowed to the public. This snippet of code just makes the isAuthorized() method honour the settings in the Auth->allow() list.

我似乎为我工作,因此我希望它会有所帮助。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....