CakePHP 3.4.3 日志记录在插件中不起作用

CakePHP 3.4.3 Logging does not work in plugin

我有登录问题。新用户注册成功,密码已加密,但我无法登录。我的登录操作在 UsersAccess 插件中,我认为这是一个问题。怎么了?

在 src/AppController 中配置身份验证:

$this->loadComponent('Auth', [
        'loginAction' => [
            'controller' => 'Users',
            'action' => 'login',
            'plugin' => 'UsersAcces'
        ],
        'loginRedirect' => [
            'plugin' => 'UsersAcces',
            'controller' => 'Users',
            'action' => 'index'
        ],
        'logoutRedirect' => [
            'controller' => 'Users',
            'action' => 'login',
            'plugin' => 'UsersAcces'
        ],
        'authError' => 'Brak dostępu!',
        'authenticate' => [
            'Form' => [
                'fields' => ['username' => 'username','password'=>'password'],
                'userModel'=>'UsersAcces.Users',
                'relatedModel' => ['UsersAcces.Roles', 'UsersAcces.Addresses', 'UsersAcces.Emails', 'UsersAcces.Permissions', 'UsersAcces.Telephones'],//'UsersAcces.Roles',
                'finder' => 'auth'
            ]
        ],
        'storage' => 'Session',
        'autoRedirect' => false
    ]);

操作登录 i plugins/UsersAcces/src/Controller/Users:

public function login(){
    $this->viewBuilder()->setLayout("login");


    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            return $this->redirect($this->Auth->redirectUrl());
        }else{
            $this->Flash->error(__('Niewłaściwy login lub hasło. Spróbuj ponownie.'));
        }
    }
    //$user = $this->Users->newEntity();
    $this->set(compact("user"));

}

plugins/UsersAcces/src/Model/Table/UsersTable 中的 findAuth 函数:

public function findAuth(\Cake\ORM\Query $query, array $options)
{   
    $query
        ->select()
        ->where(['Users._delete' => 0]);
    return $query;
}

函数 setPassword plugins/UsersAcces/src/Model/Entity/User:

protected function _setPassword($password)
{
    if (strlen($password) > 0) {
      return (new DefaultPasswordHasher)->hash($password);
    }
}

请帮忙。

您需要在 Auth 组件初始化参数中的 'Form' 键下添加密码 Hasher,例如:

'authenticate' => array( 'Form' => array( 'passwordHasher' => 'Default' ) ),

我找到了解决办法!我没有在文件 "plugins/UsersAcces/src/Controller/Users" 中添加一行:

$this->Auth->setUser($user);