Skip to content

Commit

Permalink
Optimizations, use spaces instead of tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sippsolutions committed Nov 20, 2015
1 parent 1e9572b commit ca67ef9
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* @category Sippsolutions
* @package Sippsolutions_Recaptcha
* @subpackage Helper
* @author Simon Sippert
* <[email protected]>
* @author Simon Sippert <[email protected]>
* @copyright Copyright (c) 2015 sippsolutions (http://www.sippsolutions.de)
* @version 1.0.0
* @link http://www.sippsolutions.de/
Expand Down
31 changes: 18 additions & 13 deletions app/code/community/Sippsolutions/Recaptcha/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public function checkCaptcha(Varien_Event_Observer $observer)
// get client response
$response = $request->getParam('g-recaptcha-response');

// define params object for event
$params = (object)array(
'route' => $route,
'response' => $response,
);

// check client response
if ($response) {
// create stream context
Expand All @@ -73,8 +79,11 @@ public function checkCaptcha(Varien_Event_Observer $observer)

// check response
if ($response && ($response = json_decode($response)) && $response->success) {
// set response
$params->response = $response;

// throw event
Mage::dispatchEvent('sippsolutions_recaptcha_solved');
Mage::dispatchEvent('sippsolutions_recaptcha_solved', array('config' => $params));

// proceed
return $this;
Expand All @@ -93,27 +102,23 @@ public function checkCaptcha(Varien_Event_Observer $observer)
$redirect = Mage::getUrl();
}

// define config object for event
$config = (object)array(
'route' => $route,
'response' => $response,
'should_redirect' => true,
'direct_to' => $redirect,
'message' => $helper->__('Please solve the captcha.'),
);
// set redirect
$params->should_redirect = true;
$params->redirect_to = $redirect;
$params->message = $helper->__('Please solve the captcha.');

// throw event
Mage::dispatchEvent('sippsolutions_recaptcha_redirect_before', array('config' => $config));
Mage::dispatchEvent('sippsolutions_recaptcha_redirect_before', array('config' => $params));

/** @var $session Mage_Core_Model_Session */
$session = Mage::getSingleton('core/session');

// add error message
$session->addError($config->message);
$session->addError($params->message);

// redirect to page
if ($config->should_redirect) {
header('Location: ' . $config->direct_to);
if ($params->should_redirect) {
header('Location: ' . $params->redirect_to);
die();
}

Expand Down
186 changes: 93 additions & 93 deletions app/code/community/Sippsolutions/Recaptcha/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,97 +21,97 @@
*/
-->
<config>
<modules>
<Sippsolutions_Recaptcha>
<version>1.0.0</version>
</Sippsolutions_Recaptcha>
</modules>
<frontend>
<translate>
<modules>
<sippsolutions_recaptcha>
<files>
<default>Sippsolutions_Recaptcha.csv</default>
</files>
</sippsolutions_recaptcha>
</modules>
</translate>
<layout>
<updates>
<sippsolutions_recaptcha>
<file>sippsolutions/recaptcha.xml</file>
</sippsolutions_recaptcha>
</updates>
</layout>
<events>
<controller_action_predispatch>
<observers>
<recaptcha_check>
<class>sippsolutions_recaptcha/observer</class>
<method>checkCaptcha</method>
</recaptcha_check>
</observers>
</controller_action_predispatch>
</events>
</frontend>
<adminhtml>
<translate>
<modules>
<sippsolutions_recaptcha>
<files>
<default>Sippsolutions_Recaptcha.csv</default>
</files>
</sippsolutions_recaptcha>
</modules>
</translate>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<sippsolutions_recaptcha translate="title" module="sippsolutions_recaptcha">
<title>sippsolutions_recaptcha</title>
<sort_order>50</sort_order>
</sippsolutions_recaptcha>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<models>
<sippsolutions_recaptcha>
<class>Sippsolutions_Recaptcha_Model</class>
<resourceModel>sippsolutions_recaptcha_resource</resourceModel>
</sippsolutions_recaptcha>
</models>
<helpers>
<sippsolutions_recaptcha>
<class>Sippsolutions_Recaptcha_Helper</class>
</sippsolutions_recaptcha>
</helpers>
</global>
<default>
<sippsolutions_recaptcha>
<general>
<enable>1</enable>
<only_guests>1</only_guests>
<theme>light</theme>
<size>normal</size>
</general>
<location>
<login>1</login>
<review>1</review>
<contact>1</contact>
<register>1</register>
</location>
</sippsolutions_recaptcha>
</default>
<modules>
<Sippsolutions_Recaptcha>
<version>1.0.0</version>
</Sippsolutions_Recaptcha>
</modules>
<frontend>
<translate>
<modules>
<sippsolutions_recaptcha>
<files>
<default>Sippsolutions_Recaptcha.csv</default>
</files>
</sippsolutions_recaptcha>
</modules>
</translate>
<layout>
<updates>
<sippsolutions_recaptcha>
<file>sippsolutions/recaptcha.xml</file>
</sippsolutions_recaptcha>
</updates>
</layout>
<events>
<controller_action_predispatch>
<observers>
<recaptcha_check>
<class>sippsolutions_recaptcha/observer</class>
<method>checkCaptcha</method>
</recaptcha_check>
</observers>
</controller_action_predispatch>
</events>
</frontend>
<adminhtml>
<translate>
<modules>
<sippsolutions_recaptcha>
<files>
<default>Sippsolutions_Recaptcha.csv</default>
</files>
</sippsolutions_recaptcha>
</modules>
</translate>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<sippsolutions_recaptcha translate="title" module="sippsolutions_recaptcha">
<title>sippsolutions_recaptcha</title>
<sort_order>50</sort_order>
</sippsolutions_recaptcha>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<models>
<sippsolutions_recaptcha>
<class>Sippsolutions_Recaptcha_Model</class>
<resourceModel>sippsolutions_recaptcha_resource</resourceModel>
</sippsolutions_recaptcha>
</models>
<helpers>
<sippsolutions_recaptcha>
<class>Sippsolutions_Recaptcha_Helper</class>
</sippsolutions_recaptcha>
</helpers>
</global>
<default>
<sippsolutions_recaptcha>
<general>
<enable>1</enable>
<only_guests>1</only_guests>
<theme>light</theme>
<size>normal</size>
</general>
<location>
<login>1</login>
<review>1</review>
<contact>1</contact>
<register>1</register>
</location>
</sippsolutions_recaptcha>
</default>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
-->
<jstranslator>
<recaptcha-solve translate="message" module="widget">
<message>Please solve the captcha.</message>
</recaptcha-solve>
<recaptcha-solve translate="message" module="widget">
<message>Please solve the captcha.</message>
</recaptcha-solve>
</jstranslator>
Loading

0 comments on commit ca67ef9

Please sign in to comment.