Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to use the email address when doing a reset password reque... #1116

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions wire/modules/Process/ProcessForgotPassword.module
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
// allow passwords to be reset?
$this->set('allowReset', 1);
$this->set('table', 'process_forgot_password');
$this->set('emailFrom', '');
$this->set('emailFrom', '');
$this->set('enableUseEmailForReset', 0);
}

/**
Expand Down Expand Up @@ -101,8 +102,14 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {

$field = $this->modules->get("InputfieldText");
$field->attr('id+name', 'username');
$field->required = true;
$field->label = $this->_("Enter your user name");
$field->required = true;
if ( $this->enableUseEmailForReset ) {
$field->label = $this->_("Enter your user name or email address");
}
else {
$field->label = $this->_("Enter your user name");
}

$field->description = $this->_("If you have an account in our system with a valid email address on file, an email will be sent to you after you submit this form. That email will contain a link that you may click on to reset your password.");
$form->add($field);

Expand Down Expand Up @@ -140,6 +147,16 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
// user was found, send them an email with reset link
$this->step2_sendEmail($user);
}
elseif ( $this->enableUseEmailForReset ) {
// try also with the email address
$email = $this->sanitizer->email( $this->input->post->username );
if ( strlen( $email ) && count( $this->users->find( "email=$email" ) ) == 1 ) {
$user = $this->users->get( "email=$email" );
if ( $user && $user->id && $user->email == $email && !$user->isUnpublished() ) {
$this->step2_sendEmail( $user );
}
}
}
}

$out =
Expand Down Expand Up @@ -224,6 +241,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
return;
}
}
else {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : Problems sending password reset email to '.$user->email);
}
}

/**
Expand Down Expand Up @@ -399,7 +419,15 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
$f->attr('name', 'emailFrom');
$f->label = __('Email address to send messages from');
if(isset($data['emailFrom'])) $f->attr('value', $data['emailFrom']);
$form->add($f);
$form->add($f);

$f = wire('modules')->get( 'InputfieldCheckbox' );
$f->label = __( 'Enable users to enter optionally their email address in place of their username' );
$f->attr( 'id+name', 'enableUseEmailForReset' );
$f->attr( 'value', 0 );
$f->attr( 'checked', empty( $data['enableUseEmailForReset'] ) ? '' : 'checked' );
$form->add($f);

return $form;
}

Expand Down