【问题标题】:SilverStripe visitor and permissionsSilverStripe 访客和权限
【发布时间】:2015-03-07 05:38:31
【问题描述】:

在 SilverStripe 中是否有任何关于用户和他们在登录后可以看到的内容的教程,具体取决于他们的角色和权限?

我希望用户在登录后查看更多内容,但不能访问 CMS。

我该怎么做?

【问题讨论】:

    标签: authentication permissions roles silverstripe


    【解决方案1】:

    有一些关于这个主题的详细教程Silverstripe User Help

    感兴趣的是Managing roles and permissions

    在设置组权限时,您可以设置用户是否拥有对所有 CMS、部分 CMS 或没有任何 CMS 的权限。

    您可以创建一个无法访问 CMS,但可以在前端查看额外页面的用户组。为此,在创建新组时,请在 Permissions 选项卡上取消选中所有复选框。

    然后你会想要设置一些页面只能由登录的成员访问。在 CMS 中,选择您希望仅由登录成员查看的页面。转到右上角的页面设置选项卡。在此屏幕上,您将看到谁可以查看此页面?。您可以选择登录用户仅这些人(从列表中选择),然后在输入字段中选择用户组。

    您可以通过扩展MemberLoginForm 来控制登录用户的去向。

    首先在mysite/code/CustomLoginForm.php 中创建一个CustomLoginForm 类。

    CustomLoginForm.php

    class CustomLoginForm extends MemberLoginForm  {
    
        public function dologin($data) {
            if($this->performLogin($data)) {
    
                // Check if the logging in member has access to the CMS
                if(Permission::check('CMS_ACCESS_CMSMain')) {
                    // If they do, send them to the admin page
                    $this->logInUserAndRedirect($data);
                }
    
                // If they don't, redirect them to whatever page you like. 
                // The following redirects the user to the home page
                return Controller::curr()->redirect(Director::baseURL());
    
            } else {
                if ($badLoginURL = Session::get('BadLoginURL')) {
                    return Controller::curr()->redirect($badLoginURL);
                } else {
                    return Controller::curr()->redirectBack();  
                }
            }      
        }
    
    }  
    

    在您的 _mysite/config.php 中调用 userCustomClass 函数以将 CustomLoginForm 设置为您的 `MemberLoginForm。将以下行添加到您的 _mysite/config.php 文件中:

    config.php

    Object::useCustomClass('MemberLoginForm', 'CustomLoginForm');
    

    您可以自定义它以通过 CMS 控制重定向页面,甚至可以为每个用户组设置。它只需要一点代码来添加它。

    【讨论】:

    • 我已经红了,但似乎有我想隐藏的部分 cms 的角色和权限。
    • 这是我正在寻找的线索
    • 您知道如何删除此通知吗:很抱歉,您无法访问 CMS 的该部分。如果您想以其他人身份登录,请在下面进行。当我以无法查看 CMS 的普通用户身份登录时,我得到了它
    • @user1406647 - 我已经编辑了我的答案,详细说明了如何做到这一点。
    • 我现在试试,谢谢。
    猜你喜欢
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 2021-01-09
    • 2017-10-11
    • 1970-01-01
    • 2013-05-02
    相关资源
    最近更新 更多