IMPR: Login forms

This commit is contained in:
Tony Air 2024-03-26 04:53:12 +02:00
parent 10d35e92fc
commit f6b150b866
1 changed files with 9 additions and 16 deletions

View File

@ -10,6 +10,7 @@ use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\ValidationResult; use SilverStripe\ORM\ValidationResult;
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
@ -70,23 +71,17 @@ class AjaxControllerEx extends Extension
public function LoginFormEx() public function LoginFormEx()
{ {
$ctrl = $this->owner; $ctrl = Security::singleton();
/* @var Form $form */ /* @var Form $form */
if (method_exists($ctrl, 'LoginForm')) { $form = $ctrl->getLoginForms()['default'][0];
$form = $ctrl->LoginForm();
} else {
$form = $ctrl->getLoginForms()['default'][0];
}
self::_processFields($form); self::_processFields($form);
//$form->addExtraClass('ajax-form'); //$form->addExtraClass('ajax-form');
$back = $this->owner->Link();
if (Director::isLive() && $form->get_protector()) { $form->setFormAction('/Security/login/default/LoginForm/?BackURL='.$back);
$form->enableSpamProtection(); $form->Fields()
} ->push(HiddenField::create('BackURL')->setValue($back));
$form->setLegend( $form->setLegend(
_t( _t(
@ -207,11 +202,9 @@ class AjaxControllerEx extends Extension
$url = $req->getURL(); $url = $req->getURL();
$url = $url === 'home' ? '/' : $url; $url = $url === 'home' ? '/' : $url;
$ajax_res = $ctrl->config()->get('ajax_resources');
$graphql_res = $ctrl->config()->get('graphql_resources');
$resources = array_merge( $resources = array_merge(
$ajax_res ? $ajax_res : [], $ctrl->config()->get('graphql_resources'),
$graphql_res ? $graphql_res : [] $ctrl->config()->get('ajax_resources')
); );
$body = $response->getBody(); $body = $response->getBody();