mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +02:00
Fix issue processwire/processwire-issues#310 - update ProcessForgotPassword to use the same requirements as when editing the pass field in the page editor
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2017 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
@@ -21,7 +21,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
return array(
|
||||
'title' => __('Forgot Password', __FILE__), // getModuleInfo title
|
||||
'summary' => __('Provides password reset/email capability for the Login process.', __FILE__), // getModuleInfo summary
|
||||
'version' => 101,
|
||||
'version' => 102,
|
||||
'permanent' => false,
|
||||
'permission' => 'page-view',
|
||||
);
|
||||
@@ -44,13 +44,13 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function ___execute() {
|
||||
|
||||
if($this->user->isLoggedin()) return;
|
||||
if($this->user->isLoggedin()) return '';
|
||||
|
||||
$this->wire('processHeadline', $this->_('Reset Password')); // Reset password page headline
|
||||
|
||||
if(!$this->allowReset) {
|
||||
$this->error($this->_("Password reset is not allowed"));
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->setupResetTable();
|
||||
@@ -83,7 +83,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
return $this->step1_renderForm();
|
||||
}
|
||||
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,10 +93,12 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function step1_renderForm() {
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form->attr('action', './?forgot=1');
|
||||
$form->attr('method', 'post');
|
||||
|
||||
|
||||
/** @var InputfieldText $field */
|
||||
$field = $this->modules->get("InputfieldText");
|
||||
$field->attr('id+name', 'username');
|
||||
$field->required = true;
|
||||
@@ -112,6 +115,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($field);
|
||||
*/
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $this->modules->get("InputfieldSubmit");
|
||||
$submit->attr('id+name', 'submit_forgot');
|
||||
$form->add($submit);
|
||||
@@ -132,6 +136,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$user = null;
|
||||
$name = $this->sanitizer->pageNameUTF8($this->input->post->username);
|
||||
if(strlen($name)) {
|
||||
/** @var User $user */
|
||||
$user = $this->users->get("name=" . $this->sanitizer->selectorValue($name));
|
||||
if($user && $user->id && $user->email && !$user->isUnpublished()) {
|
||||
// user was found, send them an email with reset link
|
||||
@@ -167,6 +172,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
/**
|
||||
* Send an email with password reset link to the given User account
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
*/
|
||||
protected function step2_sendEmail(User $user) {
|
||||
@@ -216,8 +223,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
} catch(\Exception $e) {
|
||||
// catch any errors, just to prevent anything from ever being reported to screen
|
||||
$this->session->clearErrors();
|
||||
$this->error("Unable to complete this step");
|
||||
$this->session->removeNotices();
|
||||
$this->errors('all clear');
|
||||
$this->error($this->_('Unable to complete this step'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -272,20 +280,30 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
/**
|
||||
* Build the form with the reset password field
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $token
|
||||
* @return InputfieldForm
|
||||
*
|
||||
*/
|
||||
protected function step3_buildForm($id, $token) {
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form->attr('method', 'post');
|
||||
$form->attr('action', "./?forgot=1&user_id=$id&token=$token");
|
||||
|
||||
$field = $this->modules->get("InputfieldPassword");
|
||||
$field->attr('id+name', 'pass');
|
||||
$field->required = true;
|
||||
$field->label = $this->_("Reset Password"); // New password field label
|
||||
$form->add($field);
|
||||
/** @var Field $field */
|
||||
$field = $this->wire('fields')->get('pass');
|
||||
/** @var InputfieldPassword $inputfield */
|
||||
$inputfield = $field->getInputfield(new NullPage(), $field);
|
||||
$inputfield->required = true;
|
||||
$inputfield->collapsed = Inputfield::collapsedNever;
|
||||
$inputfield->attr('id+name', 'pass');
|
||||
$inputfield->label = $this->_("Reset Password"); // New password field label
|
||||
$form->add($inputfield);
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $this->modules->get("InputfieldSubmit");
|
||||
$submit->attr('id+name', 'submit_reset');
|
||||
$form->add($submit);
|
||||
@@ -295,11 +313,17 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
/**
|
||||
* Process the submitted password reset form and reset password
|
||||
*
|
||||
* @param string $id
|
||||
* @param InputfieldForm $form
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
protected function step4_completeReset($id, $form) {
|
||||
|
||||
$form->processInput($this->input->post);
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->users->get((int) $id);
|
||||
$pass = $form->get('pass')->value;
|
||||
|
||||
@@ -317,6 +341,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$this->session->remove('userResetID');
|
||||
$this->session->remove('userResetName');
|
||||
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$table = $database->escapeTable($this->table);
|
||||
$query = $database->prepare("DELETE FROM `$table` WHERE id=:id");
|
||||
@@ -324,7 +349,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$query->execute();
|
||||
|
||||
$this->session->redirect("./");
|
||||
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,7 +417,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
public function getModuleConfigInputfields(array $data) {
|
||||
/** @var InputfieldWrapper $form */
|
||||
$form = $this->wire(new InputfieldWrapper());
|
||||
/** @var InputfieldEmail $f */
|
||||
$f = $this->wire('modules')->get('InputfieldEmail');
|
||||
$f->attr('name', 'emailFrom');
|
||||
$f->label = $this->_('Email address to send messages from');
|
||||
|
Reference in New Issue
Block a user