mirror of
https://github.com/processwire/processwire.git
synced 2025-08-13 18:24:57 +02:00
Minor tweaks in WireHooks, ProcessForgotPassword and SessionLoginThrottle
This commit is contained in:
@@ -783,6 +783,16 @@ class WireHooks {
|
||||
$cancelHooks = false;
|
||||
$profiler = $this->wire->wire('profiler');
|
||||
$hooks = null;
|
||||
$methodExists = false;
|
||||
|
||||
if($type === 'method') {
|
||||
$methodExists = method_exists($object, $realMethod);
|
||||
if(!$methodExists && method_exists($object, $method)) {
|
||||
// non-hookable method exists, indicating we may be in a manually called runHooks()
|
||||
$methodExists = true;
|
||||
$realMethod = $method;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($type)) {
|
||||
// array of hooks to run provided in $type argument
|
||||
@@ -793,12 +803,12 @@ class WireHooks {
|
||||
$result = array(
|
||||
'return' => null,
|
||||
'numHooksRun' => 0,
|
||||
'methodExists' => ($type === 'method' ? method_exists($object, $realMethod) : false),
|
||||
'methodExists' => $methodExists,
|
||||
'replace' => false,
|
||||
);
|
||||
|
||||
if($type === 'method' || $type === 'property' || $type === 'either') {
|
||||
if(!$result['methodExists'] && !$this->isHookedOrParents($object, $method, $type)) {
|
||||
if(!$methodExists && !$this->isHookedOrParents($object, $method, $type)) {
|
||||
return $result; // exit quickly when we can
|
||||
}
|
||||
}
|
||||
@@ -809,7 +819,7 @@ class WireHooks {
|
||||
|
||||
if($type === 'method') {
|
||||
if($when === 'after' && $result['replace'] !== true) {
|
||||
if($result['methodExists']) {
|
||||
if($methodExists) {
|
||||
$result['return'] = $object->_callMethod($realMethod, $arguments);
|
||||
} else {
|
||||
$result['return'] = null;
|
||||
|
@@ -25,6 +25,7 @@
|
||||
* @property array $confirmFields Extra field values to confirm values before accepting password change, optional. (default=['email'])
|
||||
* @property array $allowRoles Only allow password reset for these roles, optional. (default=[])
|
||||
* @property array $blockRoles Block these roles, optional. (default=[])
|
||||
* @property string $wireMailer WireMail module name to use or omit for system default. Since 3.0.148.
|
||||
*
|
||||
* @method string renderEmailBody($url, $code, $html) Render the password reset email body, and $url should appear in that email body.
|
||||
* @method string renderErrorEmailBody($error) Render error email body
|
||||
@@ -95,6 +96,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$this->set('confirmFields', array());
|
||||
$this->set('allowRoles', array());
|
||||
$this->set('blockRoles', array());
|
||||
$this->set('wireMailer', '');
|
||||
|
||||
$emailField = $this->wire('fields')->get('email');
|
||||
if($emailField) $this->set('confirmFields', array("email:$emailField->id"));
|
||||
@@ -335,9 +337,10 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$body = $this->renderEmailBody($url, $verify, false);
|
||||
$bodyHTML = $this->renderEmailBody($url, $verify, true);
|
||||
|
||||
// if(self::debug) $this->message($bodyHTML, Notice::allowMarkup);
|
||||
$email = null;
|
||||
if($this->wireMailer) $email = $this->wire('mail')->new(array('module' => $this->wireMailer));
|
||||
if(!$email) $email = $this->wire('mail')->new();
|
||||
|
||||
$email = $this->wire('mail')->new();
|
||||
$email->to($user->email)->from($this->getEmailFrom());
|
||||
$email->subject($this->emailSubject)->body($body)->bodyHTML($bodyHTML);
|
||||
|
||||
@@ -518,7 +521,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$f->attr('name', $field->name);
|
||||
$f->collapsed = Inputfield::collapsedNever;
|
||||
$f->columnWidth = 100;
|
||||
$f->notes = $this->_('Resetting password also requires that you confirm the correct value of this field.');
|
||||
$f->description = $this->_('Resetting password also requires that you confirm the correct value of this field.');
|
||||
$form->add($f);
|
||||
$confirmFields[$key] = $field->name;
|
||||
}
|
||||
|
@@ -147,7 +147,7 @@ class SessionLoginThrottle extends WireData implements Module, ConfigurableModul
|
||||
if($this->wire('process') == 'ProcessLogin') {
|
||||
parent::error($error);
|
||||
} else {
|
||||
throw new WireException($error); // ensures the error can't be missed in unknown API usage
|
||||
throw new SessionLoginThrottleException($error); // ensures the error can't be missed in unknown API usage
|
||||
}
|
||||
} else {
|
||||
$allowed = true;
|
||||
@@ -268,3 +268,9 @@ class SessionLoginThrottle extends WireData implements Module, ConfigurableModul
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when login overflow occurs and throttle is active
|
||||
*
|
||||
*/
|
||||
class SessionLoginThrottleException extends WireException { }
|
||||
|
Reference in New Issue
Block a user