diff --git a/.upgrade.yml b/.upgrade.yml index d57c41765..a2fec5e91 100644 --- a/.upgrade.yml +++ b/.upgrade.yml @@ -1325,6 +1325,8 @@ warnings: replacement: 'writeJavascriptToBody' 'SilverStripe\Forms\Formfield->dontEscape': message: 'FormField::$dontEscape has been removed. Escaping is now managed on a class by class basis.' + 'SilverStripe\Security\LoginForm->authenticator_class': + message: 'authenticator_class is deprecated. Use getAuthenticatorClass/setAuthenticatorClass.' 'SilverStripe\Security\Permission::$declared_permissions': message: 'Deprecated' 'SilverStripe\Security\Permission::$declared_permissions_list': @@ -1387,4 +1389,4 @@ warnings: url: 'https://docs.silverstripe.org/en/4/changelogs/4.4.0#resources-dir' replacement: 'RESOURCES_DIR' renameWarnings: - - Form \ No newline at end of file + - Form diff --git a/src/Security/LoginForm.php b/src/Security/LoginForm.php index f1622f5e1..a927915a9 100644 --- a/src/Security/LoginForm.php +++ b/src/Security/LoginForm.php @@ -15,26 +15,56 @@ use SilverStripe\Forms\Form; */ abstract class LoginForm extends Form { - /** - * Authenticator class to use with this login form - * - * Set this variable to the authenticator class to use with this login - * form. + * @deprecated 4.4.0:5.0.0 Use getAuthenticatorClass() or setAuthenticatorClass() instead * @var string */ protected $authenticator_class; + /** + * Authenticator class to use with this login form + * + * Set this variable to the authenticator class to use with this login form. + * + * @var string + */ + protected $authenticatorClass; + + /** + * Set the authenticator class name to use + * + * @param string $class + * @return $this + */ public function setAuthenticatorClass($class) { - $this->authenticator_class = $class; - $authenticatorField = $this->Fields()->dataFieldByName('AuthenticationMethod'); + $this->authenticatorClass = $class; + + /** @var FieldList|null $fields */ + $fields = $this->Fields(); + if (!$fields) { + return $this; + } + + $authenticatorField = $fields->dataFieldByName('AuthenticationMethod'); if ($authenticatorField) { $authenticatorField->setValue($class); } + return $this; } + /** + * Returns the authenticator class name to use + * + * @return string + */ + public function getAuthenticatorClass() + { + // B/C for deprecated authenticator_class property + return $this->authenticator_class ?: $this->authenticatorClass; + } + /** * Return the title of the form for use in the frontend * For tabs with multiple login methods, for example. diff --git a/src/Security/MemberAuthenticator/CMSMemberLoginForm.php b/src/Security/MemberAuthenticator/CMSMemberLoginForm.php index 636df9f1f..361677931 100644 --- a/src/Security/MemberAuthenticator/CMSMemberLoginForm.php +++ b/src/Security/MemberAuthenticator/CMSMemberLoginForm.php @@ -30,7 +30,7 @@ class CMSMemberLoginForm extends MemberLoginForm { $this->controller = $controller; - $this->authenticator_class = $authenticatorClass; + $this->setAuthenticatorClass($authenticatorClass); $fields = $this->getFormFields(); @@ -48,7 +48,7 @@ class CMSMemberLoginForm extends MemberLoginForm { // Set default fields $fields = FieldList::create([ - HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this), + HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this), HiddenField::create('tempid', null, $this->controller->getRequest()->requestVar('tempid')), PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password')) ]); diff --git a/src/Security/MemberAuthenticator/MemberLoginForm.php b/src/Security/MemberAuthenticator/MemberLoginForm.php index e3d345e28..f60fb68b4 100644 --- a/src/Security/MemberAuthenticator/MemberLoginForm.php +++ b/src/Security/MemberAuthenticator/MemberLoginForm.php @@ -77,7 +77,7 @@ class MemberLoginForm extends BaseLoginForm $checkCurrentUser = true ) { $this->setController($controller); - $this->authenticator_class = $authenticatorClass; + $this->setAuthenticatorClass($authenticatorClass); $customCSS = project() . '/css/member_login.css'; if (Director::fileExists($customCSS)) { @@ -88,7 +88,7 @@ class MemberLoginForm extends BaseLoginForm // @todo find a more elegant way to handle this $logoutAction = Security::logout_url(); $fields = FieldList::create( - HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this) + HiddenField::create('AuthenticationMethod', null, $this->getAuthenticatorClass(), $this) ); $actions = FieldList::create( FormAction::create('logout', _t( @@ -133,7 +133,7 @@ class MemberLoginForm extends BaseLoginForm $label = Member::singleton()->fieldLabel(Member::config()->get('unique_identifier_field')); $fields = FieldList::create( - HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this), + HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this), // Regardless of what the unique identifer field is (usually 'Email'), it will be held in the // 'Email' value, below: // @todo Rename the field to a more generic covering name