【问题标题】:silverstripe external authentificationsilverstripe 外部认证
【发布时间】:2012-08-16 00:58:04
【问题描述】:

有一个自定义登录表单可以让用户访问同一页面上的某些内容。到目前为止,这适用于在 SS 数据库中存储为成员的用户,我在登录后检查用户是否在页面类中具有这样的权限:

function isAllowed() {
    if (Member::currentUser()) {
        $PresseGroup = DataObject::get_one('Group', "Code = 'presse'");
        $AdminGroup = DataObject::get_one('Group', "Code = 'administrators'");
        if (Member::currentUser()->inGroup($PresseGroup->ID) || Member::currentUser()->inGroup($AdminGroup->ID)) {
            return true;
        }
    }
}

在模板中我刚刚做了这个:

<% if isAllowed %>  
SecretContent
<% end_if %>

到目前为止还可以,但现在用户不会存储在 silverstripe 数据库中 - 他们存储在另一台服务器上。

在那个外部服务器上正在运行一个接受用户名和密码的小 php 脚本。该脚本仅返回用户是否具有权限:true 或 false。

我正在通过 cURL 调用该脚本。

我打算覆盖 MemberLoginForm 的 dologin 函数。现在我只是想知道如何在登录后检查用户是否获得了权限并显示内容......我试图在页面的控制器中设置一个变量还是应该设置一个会话变量?那是我的尝试(CustomLoginForm 扩展了 MemberLoginForm):

public function dologin($data) {
if(userHasPermission("user1", "pw")==true){
    $this->controller->Test("test");     
}
$link = $this->controller->Link();
$this->performLogin($data);
$this->controller->redirect($link);
}

我希望有人可以帮助我解决这个问题 - 我知道非常具体 - 问题。 多谢, 弗洛里安

【问题讨论】:

    标签: content-management-system silverstripe


    【解决方案1】:

    在 SilverStripe 中,您可以创建自定义身份验证器,这意味着用户可以使用存储在其他地方的帐户登录您的网站,甚至可以使用硬编码的用户名和密码。 您可以查看OpenID Authentication Module 以了解如何操作的示例代码

    但是对于您的任务,这甚至可能是一个复杂的解决方案,登录后只需执行Session::set('isAllowed', true); 之类的操作并检查是否允许用户查看:

    function isAllowed() {
        if (Member::currentUser()) {
            $PresseGroup = DataObject::get_one('Group', "Code = 'presse'");
            $AdminGroup = DataObject::get_one('Group', "Code = 'administrators'");
            if (Member::currentUser()->inGroup($PresseGroup->ID) || Member::currentUser()->inGroup($AdminGroup->ID)) {
                return true;
            }
        }
        // if Member::currentUser() is not allowed to view, 
        // return the session, which is either set to true or it returns null if not set 
        return Session::get('isAllowed');
    }
    

    【讨论】:

      猜你喜欢
      • 2019-05-11
      • 2017-10-16
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多