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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line