【问题标题】:Authenticate users with remote server in Yii framework在 Yii 框架中使用远程服务器对用户进行身份验证
【发布时间】:2012-08-17 10:47:17
【问题描述】:

我正在为一个应用程序使用 yii 框架,我需要一组用户通过远程服务器进行身份验证。

我的应用程序中的用户角色很少。例如:

  • 超级管理员
  • 品牌管理员
  • 客户 等等……

所有客户记录都在远程 MySQL 数据库中。我必须通过我的 yii 应用程序对客户进行身份验证。我的 yii 应用程序将托管在不同的服务器上。

请假设我可以在远程服务器中放置一个 php 脚本来响应我的发布请求。

我需要编写自己的 UserIdentity 类来执行此操作吗?

请帮助我。 谢谢

【问题讨论】:

    标签: authentication yii


    【解决方案1】:

    我认为您不需要在远程服务器中放置任何脚本,您只需要

    1. Access the remote Db, and Yii allows the use of [multiple-databases][1].
    2. Adjust the model(s) you are using for Authentication/Authorization (usually the User model) to load it's data from the remote database
    

    对于第一个任务:

    // protected/main/config.php
    
    return array(
    ...
    'components' => array(
        'db' => array(
            'connectionString' => 'mysql:host=dbserver1;dbname=my1db',
            ...
        ),
        'remotedb' => array(
            'connectionString' => 'mysql:host=adserver2;dbname=advertisingDB',
            'username'         => 'username',
            'password'         => '***********',
            ...
            'class'            => 'CDbConnection'          // DO NOT FORGET THIS!
        ),
    

    第二个任务:

    对于您用于Authenticate & Authorize 的模型,您需要覆盖getDbConnection() 函数以从远程服务器加载所需的数据. 查看Wiki 了解如何

    而且,是的。您需要编写自己的 UserIdentity 类,即使您没有使用远程 Db,这实际上也是一项常规任务,因为它的默认逻辑只是一个示例,不适用于实际生产站点。

    祝你好运!

    【讨论】:

    • 您好尼米尔,感谢您的帮助。作为您的建议,我创建了另一个用于远程用户身份验证的用户模型。现在一切正常!
    【解决方案2】:

    是的,您将不得不重写组件 UserIdentity 并创建自己的规则身份验证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      相关资源
      最近更新 更多