douxiong0668 2019-05-15 12:02 采纳率: 100%
浏览 112

CakePHP Authencation登录操作

I am trying to set up the new Authencation method from CakepHP. When logging in I get the message in debug that the credentials are missing. In the request POST data the email and password fields are submitted. Am I missing something?

    /**
     * Login method
     */
    public function login()
    {
        $result = $this->Authentication->getResult();

        // regardless of POST or GET, redirect if user is logged in
        if ($result->isValid()) {
            $redirect = $this->request->getQuery('redirect', ['controller' => 'Pages', 'action' => 'display', 'home']);
            return $this->redirect($redirect);
        }

        // display error if user submitted and authentication failed
        if ($this->request->is(['post']) && !$result->isValid()) {
            $this->Flash->error('Invalid username or password');
        }
    }


public function getAuthenticationService(ServerRequestInterface $request, ResponseInterface $response)
    {
        $service = new AuthenticationService();

        $fields = [
            'username' => 'email',
            'password' => 'password'
        ];

        // Load identifiers
        $service->loadIdentifier('Authentication.Password', compact('fields'));

        // Load the authenticators, you want session first
        $service->loadAuthenticator('Authentication.Session');
        $service->loadAuthenticator('Authentication.Form', [
            'fields' => $fields,
            'loginUrl' => '/users/login'
        ]);

        return $service;
    }

EDIT: After editing the Form Authenticator options with the username/post field I get the following error: FAILURE_IDENTITY_NOT_FOUND

The SQL debug says the record is found in the Users table.

SELECT 
  Users.id AS `Users__id`, 
  Users.email AS `Users__email`, 
  Users.password AS `Users__password`, 
  Users.role AS `Users__role`, 
  Users.created AS `Users__created`, 
  Users.modified AS `Users__modified` 
FROM 
  users Users 
WHERE 
  Users.email = 'my@my.com' 
LIMIT 
  1

Users table structure

id Primary key  int(11)
email   varchar(255)    utf8mb4_general_ci
password    varchar(255)    utf8mb4_general_ci
role    varchar(255)
created datetime
modified    datetime
  • 写回答

1条回答 默认 最新

  • douban5644 2019-05-15 21:04
    关注

    Fixed, had the password in plain text. Added a new user with the default password hasher.

    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行