Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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
使用DiegstAuthenticate登录CakePHP不起作用_Cakephp_Authentication - Fatal编程技术网

使用DiegstAuthenticate登录CakePHP不起作用

使用DiegstAuthenticate登录CakePHP不起作用,cakephp,authentication,Cakephp,Authentication,我使用的是CakePHP2.3.6。在一个项目中,我必须为管理员面板和学生面板实现用户管理系统。首先,我想我可以在一个控制器中安装一个login&logout系统,比如userscoontroller。但是,后来我发现我需要两个不同的登录页面用于两个面板,这就是为什么我在学生控制器和管理员控制器中放置了两个登录函数的原因 接下来,首先,我使用会话实现了完整的用户管理系统,这意味着使用会话手动登录和注销用户。那很好。但是,最近我想,如果API中已经有代码,为什么要手动编写代码呢?因此,现在我尝试使

我使用的是CakePHP2.3.6。在一个项目中,我必须为
管理员
面板和
学生
面板实现
用户管理系统
。首先,我想我可以在一个控制器中安装一个
login&logout
系统,比如
userscoontroller
。但是,后来我发现我需要两个不同的
登录页面
用于两个面板,这就是为什么我在
学生控制器
管理员控制器
中放置了两个
登录
函数的原因

接下来,首先,我使用
会话
实现了完整的
用户管理系统
,这意味着使用
会话
手动登录和注销用户。那很好。但是,最近我想,如果API中已经有代码,为什么要手动编写代码呢?因此,现在我尝试使用
AuthComponent
来实现这一点

但是,当我将所有内容从
Session
更改为
AuthComponent
时,它的行为很奇怪。以下是
AuthComponent
的代码:

学生控制器中

public $components=array('Auth'=>array(
                            'loginRedirect'=>array('controller'=>'students','action'=>'editProfile'),
                            'logoutRedirect'=>array('controller'=>'students','action'=>'index'),
                            'authenticate'=>array('Digest'=>array('scope'=>array('User.role'=>"student"))),
                            'unauthorizedRedirect'=>array('controller'=>'students','action'=>'login')
                        )
);
public $components=array('Auth'=>array(
                            'loginRedirect'=>array('controller'=>'admins','action'=>'index'),
                            'logoutRedirect'=>array('controller'=>'admins','action'=>'index'),
                            'authenticate'=>array('Digest'=>array('scope'=>array('User.role'=>"admin"))),
                            'unauthorizedRedirect'=>array('controller'=>'admins','action'=>'login') 
                        )
);
beforeFilter
功能中:

public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login','signUp');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Student->field('name',array('Student.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Admin->field('name',array('Admin.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
登录
功能中:

public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login','signUp');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Student->field('name',array('Student.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Admin->field('name',array('Admin.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
同样,在管理员控制器中:

public $components=array('Auth'=>array(
                            'loginRedirect'=>array('controller'=>'students','action'=>'editProfile'),
                            'logoutRedirect'=>array('controller'=>'students','action'=>'index'),
                            'authenticate'=>array('Digest'=>array('scope'=>array('User.role'=>"student"))),
                            'unauthorizedRedirect'=>array('controller'=>'students','action'=>'login')
                        )
);
public $components=array('Auth'=>array(
                            'loginRedirect'=>array('controller'=>'admins','action'=>'index'),
                            'logoutRedirect'=>array('controller'=>'admins','action'=>'index'),
                            'authenticate'=>array('Digest'=>array('scope'=>array('User.role'=>"admin"))),
                            'unauthorizedRedirect'=>array('controller'=>'admins','action'=>'login') 
                        )
);
beforeFilter
功能中:

public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login','signUp');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Student->field('name',array('Student.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Admin->field('name',array('Admin.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
登录
功能中:

public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login','signUp');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Student->field('name',array('Student.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('index','login');
    $this->Auth->deny('editProfile');
    $this->layout='applicant_layout';
}
public function login(){
    if($this->request->is('post'))
        if($this->Auth->login()){
            $this->Session->setFlash('Welcome '.$this->Admin->field('name',array('Admin.id'=>$this->Auth->user('id'))));
            $this->set('title_for_layout','Login');
            $this->redirect($this->Auth->redirect());
        }else{
            $this->Session->setFlash('Invalid username or password, please try again');
            $this->set('title_for_layout','Error - Login');
        }
}
在这里,我只在
用户
数据库表中存储登录凭据(
id
用户名
密码
角色
创建
修改

我的第一个问题是:对于两个面板,
AdminsController
&
StudentsController
,是否可以在一个控制器中有一个登录/注销部分,比如说
UsersController
?怎样我只想在
userscoontroller
中为两个面板提供一个登录和注销功能,其中每个面板都有不同的登录页面,为
AuthComponent(loginDirect、logoutRedirect、scope等)提供不同的
配置

我的第二个问题是:当我使用
DigestAuthenticate
时,当我尝试从自己的登录页面登录时,会出现另一个登录
对话框。该对话框不接受任何用户名/密码。我不想要那个盒子,我想要简单的登录系统,没有任何复杂性。我只想使用digest,因为它更安全

当我注销或转到未经身份验证的用户不允许的任何页面(功能)时,它会说我应该有一个
userscocontroller
,具有
login
功能。但是,现在我为两个面板提供了不同的登录功能

那么,解决方案是什么?我应该回到基于
会话的登录/注销系统,还是应该使用摘要?我还尝试使用
表单
身份验证,但结果相同,它在
用户
控制器中查找
登录
函数

请帮帮我


谢谢

我发现这很有帮助,为什么这里没有人回应?这不是一个重要的问题,还是没有人知道解决方案?