SilverStripe 4-注销时空白页 [英] SilverStripe 4 - Blank page on logging out

查看:92
本文介绍了SilverStripe 4-注销时空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在​​此处所述,我将允许预先生成的用户使用默认的from来从SilverStripe 4网站的前端页面注销.由于登录有效而注销.

As I stated here, I would allow pre-generated users to log out from a SilverStripe 4 website front-end page, by using the default from. Logging out because log in works.

问题是,如果登录的一般用户尝试通过单击诸如Security/logout(以及Security/logout?BackURL=home/)之类的链接注销,则该用户将被重定向到空白页(仅显示页眉/页脚,如下所示)默认的Page.ss已实现).显然,控制器无法正常工作或类似,因为URL仅将我指向Security/logout,而没有后续重定向.此外,该会话没有被清除,如果我返回到用户仪表板页面,其结果仍将登录.

The problem is that if a logged generic user tries to log out by clicking on a link like Security/logout (as well as Security/logout?BackURL=home/), it being redirected to a blank page (just with header/footer visible, as the default Page.ss is implemented). Apparently the controller doesn't work or similar, because URL points me simply to Security/logout with no following redirects. Furthermore, the session is not being cleared and if I go back to the user dashboard page, it results still logged in.

因此,我尝试实现自定义身份验证器,就像我在SS 3中通常所做的那样,但是我注意到了一些小差异.然后,我同时遵循了官方文档建议的示例以寻求帮助.

So, I tried to implement a custom authenticator, as I usually do in SS 3, but I noticed some little differences. Then, I followed both the official doc and the suggested example for help.

这种情况:

MemberAuthenticator自定义类 (在 MySite/code 中)

<?php
// Definizione Namespace
namespace Greylab\Corporate\Authenticator\UtenteAuthenticator;
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;

/**
* Classe Autenticazione Utente
*/
class UtenteAuthenticator extends MemberAuthenticator
{
/**
 * Login Paziente - Getter
 * @param string $link URL di autenteicazione utente
 * @return object Form di autenticazione utente
 */
public function getLoginHandler($link)
{
    return UtenteLoginHandler::create($link, $this);
}

/**
 * Logout Paziente - Getter
 * @param string $link URL di deautenteicazione utente
 * @return object Form di deautenteicazione utente
 */
public function getLogoutHandler($link)
{
    return UtenteLogoutHandler::create($link, $this);
}
}

MemberAuthenticator \ LoginHandler自定义类 (在 MySite/code 中)

<?php
// Definizione Namespace
use SilverStripe\Security\MemberAuthenticator\LoginHandler;

use SilverStripe\Core\Injector\Injector;

/**
 * Clesse Login Utente
 */
class UtenteLoginHandler extends LoginHandler
{
    /**
     * Metodo gestione Login Utente
     * Setter
     * @param array $dati Dati form login
     * @param object $form Form login
     * @return void
     */
    public function doLogin($dati, $form)
    {
        $utente = $this->checkLogin($dati);

        // Controllo Utente
        if ($utente) {
            $request = Injector::inst()->get(HTTPRequest::class);
        $session = $request->getSession();
        $cliente = $session->set('UtenteLoginHandler.MemberID', $utente->ID);
        $profiloPaziente = Member::get()->byID($session->get('UtenteLoginHandler.MemberID'));
        $datiPaziente = $session->set('UtenteLoginHandler.Data', $dati);

            // Controllo Utente
        if ($profiloCliente) {
            $this->performLogin($profiloCliente, $datiCliente);

            return $this->redirectAfterSuccessfulLogin();
        } else {
            // Se utente invalido torna al form
            return $this->redirectBack();
        }
        } else {
            // Se utente invalido torna al form
            return $this->redirectBack();
        }
    }
}

MemberAuthenticator \ LogoutHandler自定义类 (在 MySite/code 中)

// Definizione Namespace
use SilverStripe\Security\MemberAuthenticator\LogoutHandler;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Security;
use SilverStripe\Security\IdentityStore;
use SilverStripe\Security\Member;
use SilverStripe\Control\HTTPResponse;

/**
 * Clesse Login Utente
 */
class UtenteLogoutHandler extends LogoutHandler
{
    /**
     * Metodo gestione Logout Utente
     * Setter
     * @param array $dati Dati form login
     * @param object $form Form login
     * @return HTTPResponse
     */
    public function doLogOut($utente)
    {
        // Controllo Utente
        if ($utente) {
            $request = Injector::inst()->get(HTTPRequest::class);
        $session = $request->getSession();
        $paziente = $session->get('UtenteLoginHandler.MemberID');
        $datiPaziente = $session->get('UtenteLoginHandler.Data');

        // Controllo Sessione Utente
        if ($paziente && $datiPaziente) {
            $session->clear('UtenteLoginHandler.MemberID');
            $session->clear('UtenteLoginHandler.Data');

            Security::setCurrentUser(null);

            return $this->redirectAfterLogout();
            // Tried with this approach too without success...
            /* if ($utente instanceof Member) {
            Injector::inst()->get(IdentityStore::class)->logOut($this->getRequest());
                return $this->redirectAfterLogout();
            } */
        } else {
            // Se sessione utente invalida torna al form
            return $this->redirectBack();
        }
    }
}

会员身份验证器注入 (在_MySite/ config/mysite.yml 中)

MemberAuthenticator Injection (in _MySite/config/mysite.yml)

SilverStripe\Core\Injector\Injector:
  SilverStripe\Security\Security:
    properties:
      Authenticators:
        UtenteAuthenticator: %$Greylab\Corporate\Authenticator\UtenteAuthenticator

通过此实现,什么都没有改变.

With this implementation, nothing changed.

有人可以建议我正确的方法吗?

Anyone can suggest me the right way?

提前感谢大家.

推荐答案

经过深入研究,该解决方案来自一位勇敢的正式Slack社区成员:特别感谢@

After a deep research, solution came from a brave official Slack Community member: special thanks to @kinglozzer for it.

简单来说,SS 4提供了一个全新的$LogoutURL默认参数来获取正确的注销URL.它包括登录成员SecurityID作为参数.旧的SS 3 Security/logout不足以运行该过程.因此,通过使用:

Simply, SS 4 provides a brand new $LogoutURL default parameter to obtain the right logout url. It includes the logged-in member SecurityID as parameter. The old SS 3 Security/logout isn't enough anymore to run the process. So, by using:

{$LogoutURL}&BackURL=<url>

用户将被注销并正确重定向.

User will be logged out and redirected correctly.

感谢任何人的帮助.

这篇关于SilverStripe 4-注销时空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆