silverstripe / silverstripe-realme

Other
9 stars 24 forks source link

Form Submission error #36

Open Leapfrognz opened 5 years ago

Leapfrognz commented 5 years ago

Hi guys, I get the following when clicking the real me login form button

ERROR [UNKNOWN TYPE, ERRNO 404]: 
IN POST /home/RealMeLoginForm/
Line  in 

Trace
=====
SilverStripe\Dev\CliDebugView->renderTrace()
DetailedErrorFormatter.php:119

SilverStripe\Logging\DetailedErrorFormatter->output(404, , , , )
DetailedErrorFormatter.php:54

SilverStripe\Logging\DetailedErrorFormatter->format(Array)
HTTPResponse.php:416

SilverStripe\Control\HTTPResponse->outputBody()
HTTPResponse.php:344

SilverStripe\Control\HTTPResponse->output()
index.php:27

SS4, module version 3.1.1

The documentation is light on how to add the form. I added this to my page Controller:

public function RealMeLoginForm()
    {
        $authenticator = \SilverStripe\Security\Security::singleton()->getAuthenticators();
        $handler = $authenticator['RealMe']->getLoginHandler($this->owner->Link('login'));
        $form = $handler->loginForm();
        return $form;
    }

The configuration seems to be in order. Note this is testing locally. But I should still get sent to mts through right?

madmatt commented 5 years ago

Hey @Leapfrognz can you clarify what you're trying to do there? Are you wanting to embed the large login form in a different page, or use the mini login form?

Either way, you should just be able to do this in your PageController:

public function RealMeLoginForm()
{
    return new SilverStripe\RealMe\Authenticator\LoginForm($this, __FUNCTION__);
    // or return new SilverStripe\RealMe\Authenticator\MiniLoginForm($this, __FUNCTION__);
}

You'll need to add the usual private static $allowed_actions = ['RealMeLoginForm']; as well I think.

Let me know how you get on (note: I don't think we've extensively tested the mini login form on SS4, but I know the main login form should work embedded in a random page).

madmatt commented 5 years ago

Also if the docs have led you astray at all, can you let me know where so I can tidy them up? Thanks!

Leapfrognz commented 5 years ago

Thanks Matt,

 return new SilverStripe\RealMe\Authenticator\LoginForm($this, __FUNCTION__);

This renders the same form so all good. The issue is with the submission - I get the error shown in my first post. Interestingly I dont get the usual debug(), this looks different and doesnt give me any backtrace

Leapfrognz commented 5 years ago

Also the Form method is Post. The docs say this should be GET?

<form id="LoginForm_RealMeLoginForm" action="/home/RealMeLoginForm/" method="post" enctype="application/x-www-form-urlencoded">
madmatt commented 5 years ago

I'll double-check the dos, but there are two different login forms - the 'full' form (suitable for embedding on pages) and the 'mini' form (suitable for page headers/footers).

The full form (LoginForm) is POST, the mini form MiniLoginForm is GET. This is just because of the branding guidelines that RealMe has - we need to follow their HTML/CSS/JS specs precisely, and the HTML for the full form is a <button>, the mini login form is an <a> tag.

I haven't see that error you're seeing though which is pretty odd. There's nowhere specifically in the module where we return a 404 (I don't think at least).

What is the URL you're going to when you get the 404? Is it /home/RealMeLoginForm? If so, can you confirm you've added the private static $allowed_actions to PageController, and done a flush? I can't think of any other reason it wouldn't be working...

Leapfrognz commented 5 years ago

/home/RealMeLoginForm is correct, and private static $allowed_actions = ['RealMeLoginForm']; is there, and done a flush

Leapfrognz commented 5 years ago

@madmatt Im back onto this after being diverted onto other things for the past few months. Unfortunately I'm still getting the same error. I have tried this on a fresh install CWP setup as well:

composer

"require": {
        "cwp/cwp-recipe-cms": "^2.2",
        "cwp/cwp-recipe-core": "^2.2",
        "cwp/cwp-recipe-search": "^2.2",
        "silverstripe/realme": "3.1.2",
        "onelogin/php-saml": "dev-fixes/realme-dsig-validation as 2.11.0"
    },

PageController.php:

class PageController extends BasePageController
{
    private static $allowed_actions = [
        'RealMeLoginForm'
    ];

    public function RealMeLoginForm()
    {
        $auth = Injector::inst()->get(Authenticator::class);
        $handler = $auth->getLoginHandler($this->Link('login'));
        $form = $handler->loginForm();
        return $form;
    }
}
Leapfrognz commented 5 years ago

@madmatt This is what we have working, may pay to update the docs:

<?php

use SilverStripe\Security\Security;
use SilverStripe\RealMe\Authenticator\LoginForm;
use CWP\CWP\PageTypes\BasePageController;

class PageController extends BasePageController
{
    private static $allowed_actions = [
        'RealMeLoginForm',
        'acs',
        'doLogin',
        'login'
    ];

    public function doLogin()
    {
        $authenticator = Security::singleton()->getAuthenticators();
        $handler = $authenticator['RealMe']->getLoginHandler('login');
        $handler->acs($this->request);
    }

    /**
     * Get RealMe login form for any page
     *
     * @return RealMeLoginForm
     */
    public function RealMeLoginForm()
    {
        return new LoginForm($this, __FUNCTION__);
    }
}
robbieaverill commented 5 years ago

Pull requests are always welcomed

Leapfrognz commented 5 years ago

Pull requests are always welcomed

Sure, But I want @madmatt to confirm this is the expected approach before updating the docs. Saves fuss.

madmatt commented 5 years ago

I kinda think that the better option is to not list this directly, and just rely on using the Security/LoginForm - we could leave a comment that indicates you can do this if you want, but not specifically indicate the code required? Generally most people should just use Security/login... right?