Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cakephp在登录时限制对登录屏幕的访问_Php_Cakephp - Fatal编程技术网

cakephp在登录时限制对登录屏幕的访问

cakephp在登录时限制对登录屏幕的访问,php,cakephp,Php,Cakephp,我不希望我的用户在登录后能够进入登录页面。他们必须先注销才能登录。这似乎很简单,我是不是理解错了 class UsersController extends AppController { public function isAuthorized($user) { if( $this->Auth->login() ){ return false; } else { return true; } } publi

我不希望我的用户在登录后能够进入登录页面。他们必须先注销才能登录。这似乎很简单,我是不是理解错了

class UsersController extends AppController {

public function isAuthorized($user) { 

    if( $this->Auth->login() ){ 
        return false;
    } else {
        return true;    
    }

}

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
        }
    }

}

还有注册或丢失密码等操作

基本上,您只需检查列入黑名单的控制器/操作,并重定向到主屏幕或相应的登录重定向

// Do not allow access to these public actions when already logged in
$allowed = array('Account' => array('login', 'lost_password', 'register'));
foreach ($allowed as $controller => $actions) {
        if ($this->name === $controller && in_array($this->request->action, $actions)) {
                $this->Common->flashMessage('The page you tried to access is not relevant if you are already logged in. Redirected to main page.', 'info');
                return $this->redirect($this->Auth->loginRedirect);
        }
}

我使用laravel,在这种情况下,我的
登录
路径是
过滤
如下所示

Route::get('login', array('before' => 'guest', "uses" => "SessionController@create"));
guest
是过滤器的名称,定义为
return!Auth::check()

对于CakePHP,我可以想象它会非常相似。根据当前用户是否经过身份验证,寻找一种可以过滤路由的方法