我正在尝试创建一个应用程序,其中通过在 CakePHP 上检查针对 LDAP 的输入条件来完成授权部分。我正在关注此页面中链接的文本,但我遇到了问题。我不想使用任何用户表,我对存储数据没有兴趣。我要做的就是授予用户访问权限,以防他们有任何 LDAP 凭据。我设法建立连接并检查数据,但应用程序不会保存会话,因此用户永远不会登录。你知道我做错了什么吗?
这是登录功能:
public function login() {
/*if($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash("Invalid data provided");
}
}*/
App::import('Lib', 'ldap');
if ($this->Session->read('Auth.User')) {
$this->redirect(array('controller' => 'allocations', 'action' => 'index'));
} elseif (!empty($this->data)) {
$ldap = new ldap;
if ($ldap->auth($this->Auth->request->data['User']['username'], $this->Auth->request->data['User']['password'])) {
/*$userrow = $this->User->findByUsername($this->data['User']['username']);
if (!$userrow) {
$ldap_info = $ldap->getInfo($this->data['User']['username']);
$this->data['User']['user'] = $this->data['User']['username'];
$this->data['User']['name'] = $ldap_info['name'];
$this->data['User']['group_id'] = 3; //sets the default group
$this->add();
$userrow = $this->User->findByUsername($this->data['User']['user']);
}
$user = $userrow['User'];*/
$user = array()
$this->Auth->Session->write($this->Auth->sessionKey, $user);
$this->Auth->_loggedIn = true;
$this->redirect($this->Auth->redirect());
$this->Session->setFlash('You are logged in!');
} else {
$this->Session->setFlash(__('Login Failed', true));
}
}
}
我尝试调试 ldap->auth(它基本上调用存储在外部库中的 ldap_bind 函数),并且 auth 的结果是正确的(该方法返回“true”)。所以问题必须在会话的创建中。我如何让 CakePHP 知道用户已经正确登录并且它必须存储会话?谢谢!