Merge pull request #8571 from creative-commoners/pulls/4.4/get-authenticator-class

API LoginForm::authentiator_class is now deprecated, use getters or setters instead
This commit is contained in:
Robbie Averill 2019-02-01 19:21:18 +02:00 committed by GitHub
commit d4e322b6da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 13 deletions

View File

@ -1325,6 +1325,8 @@ warnings:
replacement: 'writeJavascriptToBody' replacement: 'writeJavascriptToBody'
'SilverStripe\Forms\Formfield->dontEscape': 'SilverStripe\Forms\Formfield->dontEscape':
message: 'FormField::$dontEscape has been removed. Escaping is now managed on a class by class basis.' 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': 'SilverStripe\Security\Permission::$declared_permissions':
message: 'Deprecated' message: 'Deprecated'
'SilverStripe\Security\Permission::$declared_permissions_list': 'SilverStripe\Security\Permission::$declared_permissions_list':
@ -1387,4 +1389,4 @@ warnings:
url: 'https://docs.silverstripe.org/en/4/changelogs/4.4.0#resources-dir' url: 'https://docs.silverstripe.org/en/4/changelogs/4.4.0#resources-dir'
replacement: 'RESOURCES_DIR' replacement: 'RESOURCES_DIR'
renameWarnings: renameWarnings:
- Form - Form

View File

@ -15,26 +15,56 @@ use SilverStripe\Forms\Form;
*/ */
abstract class LoginForm extends Form abstract class LoginForm extends Form
{ {
/** /**
* Authenticator class to use with this login form * @deprecated 4.4.0:5.0.0 Use getAuthenticatorClass() or setAuthenticatorClass() instead
*
* Set this variable to the authenticator class to use with this login
* form.
* @var string * @var string
*/ */
protected $authenticator_class; 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) public function setAuthenticatorClass($class)
{ {
$this->authenticator_class = $class; $this->authenticatorClass = $class;
$authenticatorField = $this->Fields()->dataFieldByName('AuthenticationMethod');
/** @var FieldList|null $fields */
$fields = $this->Fields();
if (!$fields) {
return $this;
}
$authenticatorField = $fields->dataFieldByName('AuthenticationMethod');
if ($authenticatorField) { if ($authenticatorField) {
$authenticatorField->setValue($class); $authenticatorField->setValue($class);
} }
return $this; 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 * Return the title of the form for use in the frontend
* For tabs with multiple login methods, for example. * For tabs with multiple login methods, for example.

View File

@ -30,7 +30,7 @@ class CMSMemberLoginForm extends MemberLoginForm
{ {
$this->controller = $controller; $this->controller = $controller;
$this->authenticator_class = $authenticatorClass; $this->setAuthenticatorClass($authenticatorClass);
$fields = $this->getFormFields(); $fields = $this->getFormFields();
@ -48,7 +48,7 @@ class CMSMemberLoginForm extends MemberLoginForm
{ {
// Set default fields // Set default fields
$fields = FieldList::create([ $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')), HiddenField::create('tempid', null, $this->controller->getRequest()->requestVar('tempid')),
PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password')) PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
]); ]);

View File

@ -77,7 +77,7 @@ class MemberLoginForm extends BaseLoginForm
$checkCurrentUser = true $checkCurrentUser = true
) { ) {
$this->setController($controller); $this->setController($controller);
$this->authenticator_class = $authenticatorClass; $this->setAuthenticatorClass($authenticatorClass);
$customCSS = project() . '/css/member_login.css'; $customCSS = project() . '/css/member_login.css';
if (Director::fileExists($customCSS)) { if (Director::fileExists($customCSS)) {
@ -88,7 +88,7 @@ class MemberLoginForm extends BaseLoginForm
// @todo find a more elegant way to handle this // @todo find a more elegant way to handle this
$logoutAction = Security::logout_url(); $logoutAction = Security::logout_url();
$fields = FieldList::create( $fields = FieldList::create(
HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this) HiddenField::create('AuthenticationMethod', null, $this->getAuthenticatorClass(), $this)
); );
$actions = FieldList::create( $actions = FieldList::create(
FormAction::create('logout', _t( FormAction::create('logout', _t(
@ -133,7 +133,7 @@ class MemberLoginForm extends BaseLoginForm
$label = Member::singleton()->fieldLabel(Member::config()->get('unique_identifier_field')); $label = Member::singleton()->fieldLabel(Member::config()->get('unique_identifier_field'));
$fields = FieldList::create( $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 // Regardless of what the unique identifer field is (usually 'Email'), it will be held in the
// 'Email' value, below: // 'Email' value, below:
// @todo Rename the field to a more generic covering name // @todo Rename the field to a more generic covering name