douzhi8244 2014-02-28 07:13
浏览 12
已采纳

在cakePHP登录中有第3个字段

I have created many Authentication apps with CakePHP fairly easily. However, it's always the same: Username and Password.

I want to create a login for a user to select a company as well, and if authentication to that company fails, it returns back to the login page without having him logged on.

Reason for this is, we work in a 'Parent' company that has many children. All the administration for these children companies comes through the parent company. But now, since not all employees in the Parent company has access to all children companies, we need to check if, when they log into a certain company, they have access to that specific company. The trick is that it's a one to many relationship. One user, can have access to one company or 2 or 3 or all of them.

I have the basics of authentication down, thanks to the guide on the cakePHP site, but what would I need to change from here, to do the extra Authentication check?

  • 写回答

2条回答 默认 最新

  • dongwen3093 2014-02-28 07:42
    关注

    You have to create your own Authenticate component

    you have to implement a function that checks if your user can log in and return an array of his data if so or false otherwise.

    something like

    \Controller\Component\Auth\CompanyAuthenticate.php

    App::uses('FormAuthenticate', 'Controller/Component/Auth');
    
    class CompanyAuthenticate extends FormAuthenticate
    {
        public function authenticate(CakeRequest $request, CakeResponse $response)
        {
            $user = parent::authenticate($request, $response);
            if(!$user) 
                return false;
            else
            {
                 //check company
                 // if company is ok return $user
                 // else return false
            }
        }
    
    }
    

    Edit:

    Of course you have to tell your application you are using this kind of authentication

    So in your AppController you have to do:

    public $components = array(
        'Auth' => array(
            'authenticate' => array('Company'),
             // ... other options
            ),
        // ... other components you wish to load
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?