doze79040 2016-10-05 19:07
浏览 13

使用电子邮件字段而不是用户名字段进行身份验证CakePHP 3

I was trying to implement login functionality for a web application. I found that CakePHP not allowing authentication if I using field other than 'username'. Can you please explain how can I use email field instead of username field for authentication.

I am sharing Users table and authentication code below::

Users Table

CREATE TABLE `users` (
  `id` binary(36) NOT NULL DEFAULT 'NOT NULL\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
  `password` varchar(225) NOT NULL,
  `firstname` varchar(50) NOT NULL,
  `lastname` varchar(50) NOT NULL,
  `email` varchar(45) NOT NULL,
  `phone` varchar(15) NOT NULL DEFAULT '0',
  `dob` date NOT NULL,
  `profile_for` varchar(50) DEFAULT NULL,
  `profile_pic` varchar(255) DEFAULT NULL,
  `cover_photo` varchar(100) DEFAULT NULL,
  `package_id` binary(36) DEFAULT NULL,
  `status` enum('act','dct','hid') NOT NULL DEFAULT 'act',
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `mobile` (`phone`),
  UNIQUE KEY `email_UNIQUE` (`email`),
  KEY `package_id_idx` (`package_id`),
  CONSTRAINT `package_id` FOREIGN KEY (`package_id`) REFERENCES `packages` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Authentication Code


      $this->loadComponent('Auth', [
            'loginAction'=> [
                'controller' => 'Users',
                'action' => 'login'
            ],
            'loginRedirect'=>[
                'controller' => 'Users',
                'action' => 'dashboard'
            ],
            'logoutRedirect'=>[
                'controller' => 'Users',
                'action' => 'login'
            ],
            'authError' => 'Did you really think you are allowed to see that?',
            'authenticate' => [
                'Form' => ['email' => 'email', 'password' => 'password']
            ],
            'storage' => 'Session',
            'authorize' => array('Controller')
        ]);
  • 写回答

1条回答 默认 最新

  • dongxi0523 2016-10-06 04:42
    关注

    Change:

    'authenticate' => [
        'Form' => ['email' => 'email', 'password' => 'password']
    ],
    

    To:

    'authenticate' => [
        'Form' => ['username' => 'email', 'password' => 'password']
    ],
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名