【发布时间】:2015-03-07 05:38:31
【问题描述】:
在 SilverStripe 中是否有任何关于用户和他们在登录后可以看到的内容的教程,具体取决于他们的角色和权限?
我希望用户在登录后查看更多内容,但不能访问 CMS。
我该怎么做?
【问题讨论】:
标签: authentication permissions roles silverstripe
在 SilverStripe 中是否有任何关于用户和他们在登录后可以看到的内容的教程,具体取决于他们的角色和权限?
我希望用户在登录后查看更多内容,但不能访问 CMS。
我该怎么做?
【问题讨论】:
标签: authentication permissions roles silverstripe
有一些关于这个主题的详细教程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 控制重定向页面,甚至可以为每个用户组设置。它只需要一点代码来添加它。
【讨论】: