Silverstripe 4 - Authenticator class not found

谁说胖子不能爱 提交于 2019-12-07 19:51:18

问题


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.

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.

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.

This is the situation:

MemberAuthenticator custom class (in MySite/code)

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

/**
* Classe Autenticazione Utente
*/
class UtenteAuthenticator extends Authenticator
{
/**
 * 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);
}
}

MemberAuthenticator\LoginHandler custom class (in MySite/code)

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

/**
 * 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) {
            $cliente = Session::set('UtenteLoginHandler.MemberID', $utente->ID);
            $datiCliente = Session::set('UtenteLoginHandler.Data', $dati);

            $this->performLogin($cliente, $datiCliente);

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

MemberAuthenticator\LoginHandler custom class (in _MySite/config/mysite.yml)

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

With this implementation the system throw me this exception:

PHP Fatal error: Class 'SilverStripe\Security\MemberAuthenticator\Authenticator' not found in /Applications/MAMP/htdocs/corporate/ss_corporate/corporate/code/UtenteAuthenticator.php on line 10

Anyone can suggest me the right way?

Thanks everyone in advance.


回答1:


You might need to use

use SilverStripe\Security\MemberAuthenticator\CMSMemberAuthenticator

Check out the docs: http://api.silverstripe.org/4/SilverStripe/Security/MemberAuthenticator.html



来源:https://stackoverflow.com/questions/50406958/silverstripe-4-authenticator-class-not-found

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