问题是 usersController 中的函数 setUser 返回 null,并且没有登录用户。
对 DB 的查询正在获取用户,我可以毫无问题地看到这些字段。/tmp/sessions 中的会话文件创建正常,如果我们将配置更改为 php 会话,而不是蛋糕,也会创建它。
似乎会话已创建,但 apache 或 cake 无法读取。
相同的代码,在不同的操作系统和 php 版本中工作正常。
可以与 www-data/apache 用户的某些特定权限相关联吗?
我们正在运行 Apache2、php 7.3 并连接到 SqlServer。
代码:
//////////////////////////////////////
AppController.php
ini_set(‘allow_url_fopen’, ‘on’);
$this->loadComponent(‘Auth’, [
‘loginRedirect’ => [ ‘controller’ => ‘/’, ‘action’ => ‘home’],
‘logoutRedirect’ => [ ‘controller’ => ‘/’, ‘action’ => ‘login’],
‘authenticate’ => [
‘Form’ => [
‘fields’ => [‘username’ => ‘email’, ‘password’ => ‘password’],
‘userModel’ => ‘Usuarios’
]
],
‘storage’ => [‘className’ => ‘Session’, ‘key’ => ‘Auth.Usuario’],
‘loginAction’ => [ ‘controller’ => ‘/’, ‘action’ => ‘login’],
‘unauthorizedRedirect’ => $this->referer(),
‘authorize’ => ‘Controller’,
‘authError’ => false,
]);
$this->Auth->__set('sessionKey', 'Auth.Usuario');
///////////////////////////////////////
UsuariosController.php
public function login()
{
if($this->request->is(‘post’)){
$usuario = $this->Auth->identify();
if ($usuario) {
if($this->Auth->setUser($usuario)){
$this->Flash->sPublico(__('Ingresaste a tu cuenta.'));
return $this->redirect([
'controller' => 'Pages',
'action' => 'home'
]);
}else{
$this->Flash->ePublico(__('No se pudo acceder a la sesion!.'));
}
else{
$this->Flash->ePublico(__(‘Usuario y/o contraseña incorrectos!.’));
}
}
}
///////////////////////////////////////
$this->Auth->setUser($usuario),is the function that returns false :S
谢谢 !