1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 09:14:58 +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:
Ryan Cramer
2017-07-14 09:47:24 -04:00
parent cab20d518d
commit bf351573b0

View File

@@ -9,7 +9,7 @@
* For more details about how Process modules work, please see: * For more details about how Process modules work, please see:
* /wire/core/Process.php * /wire/core/Process.php
* *
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer * ProcessWire 3.x, Copyright 2017 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* *
@@ -21,7 +21,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
return array( return array(
'title' => __('Forgot Password', __FILE__), // getModuleInfo title 'title' => __('Forgot Password', __FILE__), // getModuleInfo title
'summary' => __('Provides password reset/email capability for the Login process.', __FILE__), // getModuleInfo summary 'summary' => __('Provides password reset/email capability for the Login process.', __FILE__), // getModuleInfo summary
'version' => 101, 'version' => 102,
'permanent' => false, 'permanent' => false,
'permission' => 'page-view', 'permission' => 'page-view',
); );
@@ -44,13 +44,13 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
*/ */
public function ___execute() { public function ___execute() {
if($this->user->isLoggedin()) return; if($this->user->isLoggedin()) return '';
$this->wire('processHeadline', $this->_('Reset Password')); // Reset password page headline $this->wire('processHeadline', $this->_('Reset Password')); // Reset password page headline
if(!$this->allowReset) { if(!$this->allowReset) {
$this->error($this->_("Password reset is not allowed")); $this->error($this->_("Password reset is not allowed"));
return; return '';
} }
$this->setupResetTable(); $this->setupResetTable();
@@ -84,6 +84,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
return $this->step1_renderForm(); return $this->step1_renderForm();
} }
return '';
} }
/** /**
@@ -92,10 +93,12 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
*/ */
protected function step1_renderForm() { protected function step1_renderForm() {
/** @var InputfieldForm $form */
$form = $this->modules->get("InputfieldForm"); $form = $this->modules->get("InputfieldForm");
$form->attr('action', './?forgot=1'); $form->attr('action', './?forgot=1');
$form->attr('method', 'post'); $form->attr('method', 'post');
/** @var InputfieldText $field */
$field = $this->modules->get("InputfieldText"); $field = $this->modules->get("InputfieldText");
$field->attr('id+name', 'username'); $field->attr('id+name', 'username');
$field->required = true; $field->required = true;
@@ -112,6 +115,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
$form->add($field); $form->add($field);
*/ */
/** @var InputfieldSubmit $submit */
$submit = $this->modules->get("InputfieldSubmit"); $submit = $this->modules->get("InputfieldSubmit");
$submit->attr('id+name', 'submit_forgot'); $submit->attr('id+name', 'submit_forgot');
$form->add($submit); $form->add($submit);
@@ -132,6 +136,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
$user = null; $user = null;
$name = $this->sanitizer->pageNameUTF8($this->input->post->username); $name = $this->sanitizer->pageNameUTF8($this->input->post->username);
if(strlen($name)) { if(strlen($name)) {
/** @var User $user */
$user = $this->users->get("name=" . $this->sanitizer->selectorValue($name)); $user = $this->users->get("name=" . $this->sanitizer->selectorValue($name));
if($user && $user->id && $user->email && !$user->isUnpublished()) { if($user && $user->id && $user->email && !$user->isUnpublished()) {
// user was found, send them an email with reset link // user was found, send them an email with reset link
@@ -168,6 +173,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
/** /**
* Send an email with password reset link to the given User account * Send an email with password reset link to the given User account
* *
* @param User $user
*
*/ */
protected function step2_sendEmail(User $user) { protected function step2_sendEmail(User $user) {
@@ -216,8 +223,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
} catch(\Exception $e) { } catch(\Exception $e) {
// catch any errors, just to prevent anything from ever being reported to screen // catch any errors, just to prevent anything from ever being reported to screen
$this->session->clearErrors(); $this->session->removeNotices();
$this->error("Unable to complete this step"); $this->errors('all clear');
$this->error($this->_('Unable to complete this step'));
return; return;
} }
} }
@@ -273,19 +281,29 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
/** /**
* Build the form with the reset password field * Build the form with the reset password field
* *
* @param string $id
* @param string $token
* @return InputfieldForm
*
*/ */
protected function step3_buildForm($id, $token) { protected function step3_buildForm($id, $token) {
/** @var InputfieldForm $form */
$form = $this->modules->get("InputfieldForm"); $form = $this->modules->get("InputfieldForm");
$form->attr('method', 'post'); $form->attr('method', 'post');
$form->attr('action', "./?forgot=1&user_id=$id&token=$token"); $form->attr('action', "./?forgot=1&user_id=$id&token=$token");
$field = $this->modules->get("InputfieldPassword"); /** @var Field $field */
$field->attr('id+name', 'pass'); $field = $this->wire('fields')->get('pass');
$field->required = true; /** @var InputfieldPassword $inputfield */
$field->label = $this->_("Reset Password"); // New password field label $inputfield = $field->getInputfield(new NullPage(), $field);
$form->add($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 = $this->modules->get("InputfieldSubmit");
$submit->attr('id+name', 'submit_reset'); $submit->attr('id+name', 'submit_reset');
$form->add($submit); $form->add($submit);
@@ -296,10 +314,16 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
/** /**
* Process the submitted password reset form and reset password * Process the submitted password reset form and reset password
* *
* @param string $id
* @param InputfieldForm $form
* @return string
*
*/ */
protected function step4_completeReset($id, $form) { protected function step4_completeReset($id, $form) {
$form->processInput($this->input->post); $form->processInput($this->input->post);
/** @var User $user */
$user = $this->users->get((int) $id); $user = $this->users->get((int) $id);
$pass = $form->get('pass')->value; $pass = $form->get('pass')->value;
@@ -317,6 +341,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
$this->session->remove('userResetID'); $this->session->remove('userResetID');
$this->session->remove('userResetName'); $this->session->remove('userResetName');
/** @var WireDatabasePDO $database */
$database = $this->wire('database'); $database = $this->wire('database');
$table = $database->escapeTable($this->table); $table = $database->escapeTable($this->table);
$query = $database->prepare("DELETE FROM `$table` WHERE id=:id"); $query = $database->prepare("DELETE FROM `$table` WHERE id=:id");
@@ -325,6 +350,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
$this->session->redirect("./"); $this->session->redirect("./");
return '';
} }
/** /**
@@ -391,7 +417,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
} }
public function getModuleConfigInputfields(array $data) { public function getModuleConfigInputfields(array $data) {
/** @var InputfieldWrapper $form */
$form = $this->wire(new InputfieldWrapper()); $form = $this->wire(new InputfieldWrapper());
/** @var InputfieldEmail $f */
$f = $this->wire('modules')->get('InputfieldEmail'); $f = $this->wire('modules')->get('InputfieldEmail');
$f->attr('name', 'emailFrom'); $f->attr('name', 'emailFrom');
$f->label = $this->_('Email address to send messages from'); $f->label = $this->_('Email address to send messages from');