Silverstripe 4:会员登录并重定向到特定页面 [英] Silverstripe 4: Member Login and Redirect to specific page
本文介绍了Silverstripe 4:会员登录并重定向到特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据他们所属的组将成功登录的成员重定向到特定页面.
I'd like to redirect Members who have successfully logged in to specific pages based on the group to which they belong.
过去,我已经能够在SS3中通过以下方式做到这一点:
In the past I've been able to do this in SS3 with the following:
CustomLoginForm.php:
class CustomLoginForm extends MemberLoginForm
{
public function dologin($data)
{
// Redirect functionality here
}
}
/mysite/_config.yml:
Injector:
MemberLoginForm:
class: CustomLoginForm
但是,这种方法不适用于Silverstripe 4.
However, this approach does not work Silverstripe 4.
我尝试过:
- 如上所述,创建一个扩展了 MemberLoginForm 的 CustomLoginForm ,定义
doLogin()
并将其与Injector一起应用 - 创建扩展 LoginHander 的 CustomLoginHandler ,定义
redirectAfterSuccessfulLogin()
并将其与Injector一起应用
- As above, creating a CustomLoginForm that extends MemberLoginForm, defining
doLogin()
and applying it with Injector - Creating a CustomLoginHandler that extends LoginHander, defining
redirectAfterSuccessfulLogin()
and applying this with Injector
这两种方法均无效.
我对如何在SS4上实现这一目标感到困惑,并希望获得任何指导!
I'm stuck with how to approach this on SS4, and would appreciate any guidance!
推荐答案
已使用以下方法解决了此问题:
Have resolved this using the following approach:
CustomLoginHander.php :
<?php
namespace MySite\Namespace\Extensions;
use SilverStripe\Security\MemberAuthenticator\LoginHandler;
use SilverStripe\Security\Security;
class CustomLoginHandler extends LoginHandler
{
protected function redirectAfterSuccessfulLogin()
{
// Login redirect methods
}
}
mysite.yml:
---
Name: myproject
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Security\MemberAuthenticator\LoginHandler:
class: MySite\Namespace\Extensions\CustomLoginHandler
这篇关于Silverstripe 4:会员登录并重定向到特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文