diff --git a/wire/modules/Process/ProcessForgotPassword.module b/wire/modules/Process/ProcessForgotPassword.module index da7bb8ac..d23e09d0 100644 --- a/wire/modules/Process/ProcessForgotPassword.module +++ b/wire/modules/Process/ProcessForgotPassword.module @@ -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); } /** @@ -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); @@ -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 = @@ -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); + } } /** @@ -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; }