Permalink
Browse files

completed feature update for duplicate submission; new record was added

  • Loading branch information...
vang
vang committed Jan 16, 2015
1 parent e14824b commit ed6e8e33bc65cfc6e0c89d37b5e67e7c65e8850a
0 .gitignore 100644 → 100755
No changes.
0 build/YUI2.4.8.jar 100644 → 100755
No changes.
@@ -10,6 +10,7 @@ protected function defineAttributes()
'timeMethodFailed' => array(AttributeType::Bool),
'honeypotMethodFailed' => array(AttributeType::Bool),
'originMethodFailed' => array(AttributeType::Bool),
'duplicateMethodFailed' => array(AttributeType::Bool),
'postData' => array(AttributeType::Mixed),
'ipAddress' => array(AttributeType::String)
);
No changes.
@@ -14,6 +14,7 @@ protected function defineAttributes()
'timeMethodFailed' => array(AttributeType::Bool),
'honeypotMethodFailed' => array(AttributeType::Bool),
'originMethodFailed' => array(AttributeType::Bool),
'duplicateMethodFailed' => array(AttributeType::Bool),
'postData' => array(AttributeType::Mixed),
'ipAddress' => array(AttributeType::String)
);
@@ -7,18 +7,21 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
const METHOD_TIME = 2;
const METHOD_ORIGIN = 3;
const METHOD_HONEYPOT = 4;
const METHOD_DUPLICATE = 5;
const METHOD_FULL_STRING = 'FULL';
const METHOD_TIME_STRING = 'TIME';
const METHOD_ORIGIN_STRING = 'ORIGIN';
const METHOD_HONEYPOT_STRING = 'HONEYPOT';
const METHOD_DUPLICATE_STRING = 'DUPLICATE';
protected $methodMap = array(self::METHOD_FULL => self::METHOD_FULL_STRING, self::METHOD_TIME => self::METHOD_TIME_STRING, self::METHOD_ORIGIN => self::METHOD_ORIGIN_STRING, self::METHOD_HONEYPOT => self::METHOD_HONEYPOT_STRING);
protected $methodMap = array(self::METHOD_FULL => self::METHOD_FULL_STRING, self::METHOD_TIME => self::METHOD_TIME_STRING, self::METHOD_ORIGIN => self::METHOD_ORIGIN_STRING, self::METHOD_HONEYPOT => self::METHOD_HONEYPOT_STRING, self::METHOD_DUPLICATE => self::METHOD_DUPLICATE_STRING);
// Used to record failed submissions when logging is enabled
public $originMethodFailed = 0;
public $honeypotMethodFailed = 0;
public $timeMethodFailed = 0;
public $duplicateMethodFailed = 0;
protected $settings;
@@ -156,7 +159,7 @@ public function verifySubmission($returnResult = false)
// 3. Figure out what validation method we need to run
$method = $req->getPost('__METHOD'); // Pipe delimited list: 1|2|3|4
$method = $this->getValidationMethods($method); // Array of methods: array('full') | array('time', 'origin', 'honeypot')
$method = $this->getValidationMethods($method); // Array of methods: array('full') | array('time', 'origin', 'honeypot', 'duplicate')
// 4. No __METHOD no validation
if($method)
@@ -234,6 +237,7 @@ public function verifyFullSubmission()
{
return craft()->sproutInvisibleCaptcha_timeMethod->verifySubmission()
&& craft()->sproutInvisibleCaptcha_originMethod->verifySubmission()
&& craft()->sproutInvisibleCaptcha_duplicateMethod->verifySubmission()
&& craft()->sproutInvisibleCaptcha_honeypotMethod->verifySubmission();
}
@@ -301,6 +305,7 @@ protected function rejectSubmission($returnResult = false)
$attributes['postData'] = json_encode($_POST);
$attributes['ipAddress'] = $_SERVER["REMOTE_ADDR"];
$attributes['originMethodFailed'] = $this->originMethodFailed;
$attributes['duplicateMethodFailed'] = $this->duplicateMethodFailed;
$attributes['honeypotMethodFailed'] = $this->honeypotMethodFailed;
$attributes['timeMethodFailed'] = $this->timeMethodFailed;
@@ -369,7 +374,7 @@ protected function approveSubmission($returnResult = false)
public function getFullProtection()
{
return craft()->sproutInvisibleCaptcha_timeMethod->getField() . craft()->sproutInvisibleCaptcha_originMethod->getField() . craft()->sproutInvisibleCaptcha_honeypotMethod->getField();
return craft()->sproutInvisibleCaptcha_timeMethod->getField() . craft()->sproutInvisibleCaptcha_originMethod->getField() . craft()->sproutInvisibleCaptcha_honeypotMethod->getField() . craft()->sproutInvisibleCaptcha_duplicateMethod->getField();
}
//-------------------------------------------------------------------------------
@@ -7,18 +7,21 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
const METHOD_TIME = 2;
const METHOD_ORIGIN = 3;
const METHOD_HONEYPOT = 4;
const METHOD_DUPLICATE = 5;
const METHOD_FULL_STRING = 'FULL';
const METHOD_TIME_STRING = 'TIME';
const METHOD_ORIGIN_STRING = 'ORIGIN';
const METHOD_HONEYPOT_STRING = 'HONEYPOT';
const METHOD_DUPLICATE_STRING = 'DUPLICATE';
protected $methodMap = array(self::METHOD_FULL => self::METHOD_FULL_STRING, self::METHOD_TIME => self::METHOD_TIME_STRING, self::METHOD_ORIGIN => self::METHOD_ORIGIN_STRING, self::METHOD_HONEYPOT => self::METHOD_HONEYPOT_STRING);
protected $methodMap = array(self::METHOD_FULL => self::METHOD_FULL_STRING, self::METHOD_TIME => self::METHOD_TIME_STRING, self::METHOD_ORIGIN => self::METHOD_ORIGIN_STRING, self::METHOD_HONEYPOT => self::METHOD_HONEYPOT_STRING, self::METHOD_DUPLICATE => self::METHOD_DUPLICATE_STRING);
// Used to record failed submissions when logging is enabled
public $originMethodFailed = 0;
public $honeypotMethodFailed = 0;
public $timeMethodFailed = 0;
public $duplicateMethodFailed = 0;
protected $settings;
@@ -156,7 +159,7 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
// 3. Figure out what validation method we need to run
$method = $req->getPost('__METHOD'); // Pipe delimited list: 1|2|3|4
$method = $this->getValidationMethods($method); // Array of methods: array('full') | array('time', 'origin', 'honeypot')
$method = $this->getValidationMethods($method); // Array of methods: array('full') | array('time', 'origin', 'honeypot', 'duplicate')
// 4. No __METHOD no validation
if($method)
@@ -204,7 +207,7 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
if($this->verifyFullSubmission()==true)
return false;//this means they all pass the spam tests
else
return true; //this means one test failed and its spam!
return true; //this means at least one test failed and its spam!
}
$file = 'SproutInvisibleCaptcha_' . ucfirst(strtolower($method)) . 'MethodService.php';
@@ -218,7 +221,7 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
if (!craft()->$service->verifySubmission())
{
return true; //return true because it failed the test, its SPAM!
return false; //return true because it failed the test, its SPAM!
}
}
}
@@ -234,6 +237,7 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
{
return craft()->sproutInvisibleCaptcha_timeMethod->verifySubmission()
&& craft()->sproutInvisibleCaptcha_originMethod->verifySubmission()
&& craft()->sproutInvisibleCaptcha_duplicateMethod->verifySubmission()
&& craft()->sproutInvisibleCaptcha_honeypotMethod->verifySubmission();
}
@@ -301,6 +305,7 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
$attributes['postData'] = json_encode($_POST);
$attributes['ipAddress'] = $_SERVER["REMOTE_ADDR"];
$attributes['originMethodFailed'] = $this->originMethodFailed;
$attributes['duplicateMethodFailed'] = $this->duplicateMethodFailed;
$attributes['honeypotMethodFailed'] = $this->honeypotMethodFailed;
$attributes['timeMethodFailed'] = $this->timeMethodFailed;
@@ -369,7 +374,7 @@ class SproutInvisibleCaptchaService extends BaseApplicationComponent
public function getFullProtection()
{
return craft()->sproutInvisibleCaptcha_timeMethod->getField() . craft()->sproutInvisibleCaptcha_originMethod->getField() . craft()->sproutInvisibleCaptcha_honeypotMethod->getField();
return craft()->sproutInvisibleCaptcha_timeMethod->getField() . craft()->sproutInvisibleCaptcha_originMethod->getField() . craft()->sproutInvisibleCaptcha_honeypotMethod->getField() . craft()->sproutInvisibleCaptcha_duplicateMethod->getField();
}
//-------------------------------------------------------------------------------
@@ -0,0 +1,38 @@
<?php
namespace Craft;
class SproutInvisibleCaptcha_DuplicateMethodService extends BaseApplicationComponent implements SproutInvisibleCaptcha_MethodInterfaceService
{
//basically we give the form a unique id and clear it after a successful submit.
//if the form is submited more than once then the 'form_token' doesn't get set properly thus
//automatically returning a spam report the second time. Only the first submission will be recorded.
public function verifySubmission()
{
if(isset($_SESSION['form_token']))
{
unset($_SESSION['form_token']);
return true;
}
else
{
craft()->sproutInvisibleCaptcha->duplicateMethodFailed = 1;
return false;
}
}
public function getProtection()
{
/*** create the unique token ***/
$form_token = uniqid();
/*** create session variable ***/
$_SESSION['form_token'] = $form_token;
return $this->getField();
}
public function getField()
{
}
}
@@ -0,0 +1,38 @@
<?php
namespace Craft;
class SproutInvisibleCaptcha_DuplicateMethodService extends BaseApplicationComponent implements SproutInvisibleCaptcha_MethodInterfaceService
{
//basically we give the form a unique id and clear it after a successful submit.
//if the form is submited more than once then the 'form_token' doesn't get set properly thus
//automatically returning a spam report the second time. Only the first submission will be recorded.
public function verifySubmission()
{
if(isset($_SESSION['form_token']))
{
unset($_SESSION['form_token']);
return true;
}
else
{
craft()->sproutInvisibleCaptcha->duplicateMethodFailed = 1;
return false;
}
}
public function getProtection()
{
/*** create the unique token ***/
$form_token = uniqid();
/*** create session variable ***/
$_SESSION['form_token'] = $form_token;
return $this->getField();
}
public function getField()
{
}
}
No changes.
@@ -37,7 +37,20 @@
</div>
</div>
<div class="method-duplicate">
<label>
<input type="checkbox" value="duplicate" name="captchaMethod[]" {% if plugin.isMethodSet('duplicate') %}checked{% endif %}>
Prevents duplicate submissions (Duplicate)
</label>
<span class="more-info">?</span>
<div class="note">
<p>Prevents duplicate submission of forms. The <b>Duplicate</b> spam prevention method uses a randomly generated token to verify that a form is only submitted once to the database.</p>
<p><b>Note:</b> This method will help block multiple submissions.</p>
</div>
</div>
<div class="option method-honeypot">
<div>
Oops, something went wrong.

0 comments on commit ed6e8e3

Please sign in to comment.