问题
I'd like to redirect Members who have successfully logged in to specific pages based on the group to which they belong.
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
However, this approach does not work Silverstripe 4.
I have tried:
- 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
Neither of these methods have worked.
I'm stuck with how to approach this on SS4, and would appreciate any guidance!
回答1:
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
来源:https://stackoverflow.com/questions/52608628/silverstripe-4-member-login-and-redirect-to-specific-page