Skip to content

Commit

Permalink
Change from forward to redirect and implement own exception to circum…
Browse files Browse the repository at this point in the history
…vent core bug

FIXES #66
  • Loading branch information
Schrank committed Dec 3, 2020
1 parent f891cd4 commit e3c780f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
11 changes: 11 additions & 0 deletions app/code/community/Hackathon/HoneySpam/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

class Hackathon_HoneySpam_Exception extends Mage_Core_Controller_Varien_Exception
{
public function prepareRedirect($path, $arguments = [])
{
$this->_resultCallback = self::RESULT_REDIRECT;
$this->_resultCallbackParams = [$path, $arguments];
return $this;
}
}
24 changes: 14 additions & 10 deletions app/code/community/Hackathon/HoneySpam/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Hackathon_HoneySpam_Model_Observer
{
/**
* call rules
* @throws Mage_Core_Controller_Varien_Exception
*
* @throws Hackathon_HoneySpam_Exception
*/
public function checkHoneypotCustomerAccountCreatepost()
{
Expand Down Expand Up @@ -57,23 +58,25 @@ public function checkHoneypot()

/**
* validate honeypot field
* @throws Mage_Core_Controller_Varien_Exception
*
* @throws Hackathon_HoneySpam_Exception
*/
protected function _checkHoneypot()
{
$helper = $this->getHelper();
if ($helper->isHoneypotFilled()) {
$helper->log('Honeypot Input filled. Aborted.', Zend_Log::WARN);

$e = new Mage_Core_Controller_Varien_Exception();
$e->prepareForward('index', 'error', 'honeyspam');
$e = new Hackathon_HoneySpam_Exception();
$e->prepareRedirect('honeyspam/error/index');
throw $e;
}
}

/**
* validate time
* @throws Mage_Core_Controller_Varien_Exception
*
* @throws Hackathon_HoneySpam_Exception
*/
protected function _checkTimestamp()
{
Expand All @@ -85,8 +88,8 @@ protected function _checkTimestamp()
) {
$helper->log('Honeypot Timestamp filled. Aborted.', Zend_Log::WARN);

$e = new Mage_Core_Controller_Varien_Exception();
$e->prepareForward('index', 'error', 'honeyspam');
$e = new Hackathon_HoneySpam_Exception();
$e->prepareRedirect('honeyspam/error/index');
throw $e;
}
}
Expand All @@ -101,7 +104,8 @@ public function checkHoneypotCustomerAccountCreate()

/**
* Invoke indexing
* @throws Mage_Core_Controller_Varien_Exception
*
* @throws Hackathon_HoneySpam_Exception
*/
protected function _indexLoginParams()
{
Expand All @@ -110,8 +114,8 @@ protected function _indexLoginParams()
if ($return >= $helper->getSpamIndexLevel()) {
$helper->log("Honeypot spam index at $return. Aborted.", Zend_Log::WARN);

$e = new Mage_Core_Controller_Varien_Exception();
$e->prepareForward('index', 'error', 'honeyspam');
$e = new Hackathon_HoneySpam_Exception();
$e->prepareRedirect('honeyspam/error/index');
throw $e;
}
}
Expand Down

0 comments on commit e3c780f

Please sign in to comment.