Post by ModchipMan_AUS » Fri Aug 28, 2015 12:18 pm

Hi
OpenCart 2.0.3.1

I wanted Google reCaptcha on the registration page, I found one someone was selling, but you needed VqMod well I dont like mod integration as its not good for other reasons.
So What I have done and seems to work fine.
Enabled and got reCaptcha working on site first.

Edited register.tpl
added this code where I wanted recaptcha to be

Code: Select all

<?php if ($site_key) { ?>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="g-recaptcha" data-sitekey="<?php echo $site_key; ?>"></div>
                <?php if ($error_captcha) { ?>
                  <div class="text-danger"><?php echo $error_captcha; ?></div>
                <?php } ?>
              </div>
            </div>
<?php } ?>
Then edited register.php

Code: Select all

$data['breadcrumbs'][] = array(
	'text' => $this->language->get('heading_title'),
	'href' => $this->url->link('information/contact')
);

Code: Select all

if (isset($this->error['captcha'])) {
		$data['error_captcha'] = $this->error['captcha'];
	} else {
		$data['error_captcha'] = '';
}

Code: Select all

if ($this->config->get('config_google_captcha_status')) {
	$this->document->addScript('https://www.google.com/recaptcha/api.js');
		$data['site_key'] = $this->config->get('config_google_captcha_public');
	} else {
		$data['site_key'] = '';
}

Code: Select all

if ($this->config->get('config_google_captcha_status')) {
		$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $this->request->post['g-recaptcha-response'] . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
		$recaptcha = json_decode($recaptcha, true);
	if (!$recaptcha['success']) {
		$this->error['captcha'] = $this->language->get('error_captcha');
	}
}
Seemed to work a treat once I found the right places for the code
I'm no coder, but copy & Paste works for me..

I'm after feed back on security with this method and if it will break OpenCart..

site where i have the code is http://speedlogger.net/online/index.php ... t/register check it out working..

Thanks for reading
Tony....

Image


User avatar

Posts

Joined
Fri Aug 28, 2015 10:53 am
Location - South Australia

Post by straightlight » Wed Sep 09, 2015 9:14 am

I'm after feed back on security with this method and if it will break OpenCart..
Knowing that Opencart out of the box already delivers this solution, I would still suggest to use cURL rather than file_get_contents to pull the data; not due to security issues to answer your question but rather for optimization issues.

However, in this case, the file_get_contents is only being used once which shouldn't compromise anything except the length of the response string being returned to the function.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by bbesupplements » Sat Nov 14, 2015 4:06 am

OK. Well I know less code than you and I am in the same boat with a theme that doesn't work with recaptcha.

Your theme is probably different than mine but why is all your code in separate snipits? I can't figure out where to put what and what existing code I need to replace etc.

Any help would be great.


Posts

Joined
Sat Nov 14, 2015 4:02 am
Who is online

Users browsing this forum: No registered users and 2 guests