Reputation: 561
Default forgot password form is an Email
form field. I have a licence number attached to each user. As a user, I want to get the reset password link by entering my licence number instead of email.
I've found a way around to override the functionality side but not the form. What I've done till now
Filename: _config.php
Object::useCustomClass('MemberLoginForm', 'ExtendLoginForm');
Filename: ExtendLoginForm.php
Just as a test - override forgotPassword
method
class ExtendLoginForm extends MemberLoginForm
{
public function forgotPassword($data) {
// Ensure password is given
$this->sessionMessage('This works', 'bad');
$this->controller->redirect('Security/lostpassword');
return;
}
}
Session message is successfully printed with a redirect to the same page.
How can I override the form to make it a Text
field instead of Email
field.
Upvotes: 2
Views: 1239
Reputation: 1584
First, just a general tip, you should avoid using Object::useCustomClass() in favour of Injector (https://docs.silverstripe.org/en/3.0/reference/injector/). Object::useCustomClass() is more of a 2.4 thing.
The forgot password form is generated in Security
. You can try using a custom implementation of that class as well, and overloading the ForgotPasswordForm
method.
config.yml
Injector:
Security:
class: MyCustomSecurity
MyCustomSecurity.php
class MyCustomSecurity extends Security
{
public function LostPasswordForm()
{
$form = parent::LostPasswordForm();
$form->Fields()->replaceField('Email', TextField::create('Email'));
return $form;
}
}
Upvotes: 9