dov11020 2017-05-03 13:42
浏览 38
已采纳

在cakephp 3.x中为前端用户和管理员分别进行身份验证

We are working on a project where are 4 roles. But in cakephp 3.x Auth component holds authenticate user data in session with Auth.User indexing using

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

Due to this we are not able to access front-end user account from admin panel for some purpose, because of when we login to front-end user from admin panel, front-end login action performs and over write of session value.

So if there is any process to handle this please suggest us.

Thank you in advance.

  • 写回答

3条回答 默认 最新

  • doudou0612 2017-05-06 11:15
    关注

    As well I have understood that you are not using prefix to manage back-end and front-end user then may be you worked with separate folder structure for back-end, May I right?

    You are right that $this->Auth->setUser($user); always holds session with Auth.User indexing. So you need to write different session indexing for back-end, and you can do it as follow :

    For back-end user authentication : **

    $this->loadComponent('Auth', [
                    'authorize' => ['Controller'], // Added this line
                    'loginRedirect' => [
                        'controller' => 'Users',
                        'action' => 'dashboard',
                        'prefix' => 'admin_panel'
                    ],
                    'logoutRedirect' => [
                        'controller' => 'Users',
                        'action' => 'login',
                        'prefix' => 'admin_panel'
                    ],
                    'storage' => [
                        'className' => 'Session',
                        'key' => 'Auth.Admin',              
                    ]
                ]);
    

    **

    Here you can pass your desired index in 'storage' array key value. I think it'll works for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥40 宿舍管理系统设计(c#)
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串