Skip to content

Commit

Permalink
clean up (the removed functionality is in the parent)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasstislav committed May 29, 2021
1 parent 3c279a2 commit 7bb3c59
Showing 1 changed file with 9 additions and 70 deletions.
79 changes: 9 additions & 70 deletions code/forms/UsernameOrEmailLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,19 @@ class UsernameOrEmailLoginForm extends MemberLoginForm

public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
{
$form_action_url = Controller::join_links(
BASE_URL,
"Security",
$name
);

$lost_password_url = Controller::join_links(
BASE_URL,
"Security",
"lostpassword"
);

if (isset($_REQUEST['BackURL'])) {
$backURL = $_REQUEST['BackURL'];
} else {
$backURL = Session::get('BackURL');
}

$fields = new FieldList(
HiddenField::create(
"AuthenticationMethod",
null,
$this->authenticator_class,
$this
),
$identity_field = TextField::create(
'Identity',
_t('AuthUsernameOrEmail.UsernameOrEmail', 'Username or Email')
),
PasswordField::create(
"Password",
_t('Member.PASSWORD', 'Password')
)
);

if(!Security::config()->remember_username) {
// Some browsers won't respect this attribute unless it's added to the form
$this->setAttribute('autocomplete', 'off');
$identity_field->setAttribute('autocomplete', 'off');
}

if(Security::config()->autologin_enabled) {
$fields->push(new CheckboxField(
"Remember",
_t('Member.REMEMBERME', "Remember me?")
));
}


if (isset($backURL)) {
$fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
}
parent::__construct($controller, $name, $fields, $actions);

$actions = new FieldList(
FormAction::create('dologin', _t('Member.BUTTONLOGIN', "Log in")),
LiteralField::create(
'forgotPassword',
'<p id="ForgotPassword"><a href="' . $lost_password_url . '">'
. _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
)
$identity_field = TextField::create(
'Identity',
_t('AuthUsernameOrEmail.UsernameOrEmail', 'Username or Email'),
null,
null,
$this
);

// Reduce attack surface by enforcing POST requests
$this->setFormMethod('POST', true);
$this->Fields()->replaceField("Email", $identity_field);

// LoginForm does its magic
parent::__construct($controller, $name, $fields, $actions);
$this->setValidator(RequiredFields::create('Identity', 'Password'));

// Focus on the identity input when the page is loaded
$js = <<<JS
Expand All @@ -83,13 +29,6 @@ public function __construct($controller, $name, $fields = null, $actions = null,
})();
JS;
Requirements::customScript($js, 'UsernameOrEmailLoginFormFieldFocus');

$this
->setAttribute("action",$form_action_url);

$this
->setValidator(RequiredFields::create('Identity', 'Password'));

}

/**
Expand Down

0 comments on commit 7bb3c59

Please sign in to comment.