IMPR: Allow to disable login form captcha

This commit is contained in:
Tony Air 2022-02-18 17:10:14 +02:00
parent 3ef97b0567
commit 5efdcfb0e5

View File

@ -1,15 +1,15 @@
<?php <?php
namespace A2nt\CMSNiceties\Extensions; namespace A2nt\CMSNiceties\Extensions;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Security\MemberAuthenticator\MemberLoginForm; use SilverStripe\Security\MemberAuthenticator\MemberLoginForm;
class SiteMemberLoginForm extends MemberLoginForm class SiteMemberLoginForm extends MemberLoginForm
{ {
public function __construct( private static $enable_captcha = true;
public function __construct(
$controller, $controller,
$authenticatorClass, $authenticatorClass,
$name, $name,
@ -17,35 +17,35 @@ class SiteMemberLoginForm extends MemberLoginForm
$actions = null, $actions = null,
$checkCurrentUser = true $checkCurrentUser = true
) { ) {
parent::__construct($controller, $authenticatorClass, $name, $fields, $actions, $checkCurrentUser); parent::__construct($controller, $authenticatorClass, $name, $fields, $actions, $checkCurrentUser);
$fields = $this->Fields(); $fields = $this->Fields();
$actions = $this->Actions(); $actions = $this->Actions();
$email = $fields->fieldByName('Email'); $email = $fields->fieldByName('Email');
if ($email) { if ($email) {
$email $email
->setAttribute('placeholder', 'your@email.com') ->setAttribute('placeholder', 'your@email.com')
->setAttribute('autocomplete', 'email') ->setAttribute('autocomplete', 'email')
->setAttribute('type', 'email'); ->setAttribute('type', 'email');
} }
$pass = $fields->fieldByName('Password'); $pass = $fields->fieldByName('Password');
if($pass) { if ($pass) {
//$pass->setAttribute('autocomplete', 'current-password'); //$pass->setAttribute('autocomplete', 'current-password');
$pass->setAttribute('placeholder', '**********'); $pass->setAttribute('placeholder', '**********');
$pass->setAutofocus(true); $pass->setAutofocus(true);
} }
$btn = $actions->fieldByName('action_doLogin'); $btn = $actions->fieldByName('action_doLogin');
if($btn) { if ($btn) {
$btn->setUseButtonTag(true); $btn->setUseButtonTag(true);
$btn->setButtonContent('<i class="fas fa-check"></i> '.$btn->Title()); $btn->setButtonContent('<i class="fas fa-check"></i> '.$btn->Title());
$btn->addExtraClass('btn-lg'); $btn->addExtraClass('btn-lg');
} }
if (Director::isLive()) { if (self::config()->get('enable_captcha') && Director::isLive()) {
$this->enableSpamProtection(); $this->enableSpamProtection();
} }
} }
} }