Silverstripe 4: Member Login and Redirect to specific page

萝らか妹 提交于 2019-12-13 18:31:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!