Skip to content

Commit

Permalink
#1546 progress
Browse files Browse the repository at this point in the history
Issue with register and invisible recaptcha but none of the other
methods or locations!??!?
  • Loading branch information
abrookbanks committed Mar 10, 2017
1 parent df1949f commit b78308c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion classes/cubecart.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,7 @@ private function _register() {
}

if (!$GLOBALS['user']->is()) {
// Email validation thingy will go here

if ($GLOBALS['gui']->recaptchaRequired()) {
$GLOBALS['gui']->recaptchaAssign();
}
Expand Down
21 changes: 13 additions & 8 deletions classes/gui.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class GUI {
* @var string
*/
private $_template_dir = '';
/**
* reCAPTCHA v1 keys
*
* @var string
*/
private $_reCAPTCHA_keys = array('captcha_private' => '6LfT4sASAAAAAKQMCK9w6xmRkkn6sl6ORdnOf83H', 'captcha_public' => '6LfT4sASAAAAAOl71cRz11Fm0erGiqNG8VAfKTHn');
/**
* Postfix string for mobile config variables
*
Expand Down Expand Up @@ -687,13 +693,14 @@ public function perPageSplits($list_id = 'products', $page_key = 'perpage') {
*/
public function recaptchaAssign() {
if($GLOBALS['config']->get('config', 'recaptcha')==1) {
require_once CC_INCLUDES_DIR.'lib/recaptcha/recaptchalib.php';
$GLOBALS['smarty']->assign('LANG_RECAPTCHA', array(
'reload_words' => sprintf($GLOBALS['language']->recaptcha['reload_words'], 'javascript:Recaptcha.reload()', "javascript:Recaptcha.switch_type('audio')"),
'reload_numbers' => sprintf($GLOBALS['language']->recaptcha['reload_numbers'], 'javascript:Recaptcha.reload()', "javascript:Recaptcha.switch_type('image')"),
));
if ($GLOBALS['gui']->recaptchaRequired()) {
$GLOBALS['smarty']->assign('DISPLAY_RECAPTCHA', recaptcha_get_html($GLOBALS['recaptcha_keys']['captcha_public'], $GLOBALS['recaptcha']['error'], CC_SSL));
$GLOBALS['smarty']->assign('RECAPTCHA', true);
$GLOBALS['smarty']->assign('DISPLAY_RECAPTCHA', recaptcha_get_html($this->_reCAPTCHA_keys['captcha_public'], $GLOBALS['recaptcha']['error'], CC_SSL));
$GLOBALS['smarty']->assign('RECAPTCHA', 1);
}
}
}
Expand All @@ -702,9 +709,9 @@ public function recaptchaAssign() {
* Do we require Recaptcha check?
*/
public function recaptchaRequired() {
$version = $GLOBALS['config']->get('config', 'recaptcha');
$GLOBALS['smarty']->assign('RECAPTCHA', $version);
if($GLOBALS['config']->get('config', 'recaptcha') && !$GLOBALS['session']->get('confirmed', 'recaptcha')) {
$version = $GLOBALS['config']->get('config', 'recaptcha');
$GLOBALS['smarty']->assign('RECAPTCHA', $version);
return true;
}
return false;
Expand Down Expand Up @@ -740,10 +747,8 @@ public function recaptchaValidate() {
}
$GLOBALS['session']->set('', $recaptcha, 'recaptcha');
} elseif(isset($_POST['recaptcha_response_field'])) { // for reCAPTCHA v1
require CC_INCLUDES_DIR.'lib/recaptcha/recaptchalib.php';
$GLOBALS['recaptcha_keys'] = array('captcha_private' => '6LfT4sASAAAAAKQMCK9w6xmRkkn6sl6ORdnOf83H', 'captcha_public' => '6LfT4sASAAAAAOl71cRz11Fm0erGiqNG8VAfKTHn');

$resp = recaptcha_check_answer($GLOBALS['recaptcha_keys']['captcha_private'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
require_once CC_INCLUDES_DIR.'lib/recaptcha/recaptchalib.php';
$resp = recaptcha_check_answer($this->_reCAPTCHA_keys['captcha_private'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if ($resp->is_valid) {
$recaptcha['confirmed'] = true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions skins/foundation/templates/content.recaptcha.head.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{if $RECAPTCHA==='2' || $RECAPTCHA==='3'}
{if $RECAPTCHA=='2' || $RECAPTCHA=='3'}
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
{/if}
{if $RECAPTCHA==='3'}
{if $RECAPTCHA=='3'}
<script>
function recaptchaSubmit(token) {
$('.g-recaptcha').closest("form").submit();
Expand Down
4 changes: 2 additions & 2 deletions skins/foundation/templates/content.recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* Email: sales@cubecart.com
* License: GPL-3.0 https://www.gnu.org/licenses/quick-guide-gplv3.html
*}
{if $RECAPTCHA==='1' || $RECAPTCHA==='2'}
{if $RECAPTCHA=='1' || $RECAPTCHA=='2'}
<h3>{$LANG.form.verify_human}</h3>
<div class="row">
<div class="medium-8 columns">
{if $RECAPTCHA==='2'}
{if $RECAPTCHA=='2'}
{if empty($CONFIG.recaptcha_public_key) || empty($CONFIG.recaptcha_secret_key)}
<p>{$LANG.form.recaptcha_key_not_set}</p>
{else}
Expand Down
2 changes: 1 addition & 1 deletion skins/foundation/templates/element.recaptcha.invisible.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{if $RECAPTCHA==='3'}
{if $RECAPTCHA=='3'}
data-sitekey="{$CONFIG.recaptcha_public_key}" data-callback="recaptchaSubmit"
{/if}

0 comments on commit b78308c

Please sign in to comment.