Jump to content
Sign in to follow this  
a155

Captcha на странице авторизации(account/login)

Recommended Posts

Кто нибудь может подсказать, как прикрутить Google reCAPTCHA на страницу авторизации клиентов на OpenCart 2.0.3.1 ?

Заметил постоянные заходы ботов на эту страницу с вводом email, после чего email сохраняется в базе в разделе `oc_customer_login`

 

Share this post


Link to post
Share on other sites
# oc 2.1.*
# 1. catalog/controller/account/login.php

# Index Function
# найти
$data['column_left'] = $this->load->controller('common/column_left');
# добавить выше
if ($this->config->get($this->config->get('config_captcha') . '_status')) {
	$data['captcha'] = $this->load->controller('captcha/' . $this->config->get('config_captcha'));
} else {
	$data['captcha'] = '';
}

# Validate Function
# Найти
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']); 
# добавить выше
if ($this->config->get($this->config->get('config_captcha') . '_status')) {
	$captcha = $this->load->controller('captcha/' . $this->config->get('config_captcha') . '/validate');

	if ($captcha) {
		$this->error['warning'] = $captcha;
	}
}
# 2. catalog/view/theme/ВАША ТЕМА/template/account/login.tpl

# найти
<input type="submit" value="<?php echo $button_login; ?>" class="btn btn-primary" />
# добавить ниже
<?php echo $captcha; ?>

 

Share this post


Link to post
Share on other sites
39 минут назад, Designer сказал:
# oc 2.1.*
# 1. catalog/controller/account/login.php

# Index Function
# найти
$data['column_left'] = $this->load->controller('common/column_left');
# добавить выше
if ($this->config->get($this->config->get('config_captcha') . '_status')) {
	$data['captcha'] = $this->load->controller('captcha/' . $this->config->get('config_captcha'));
} else {
	$data['captcha'] = '';
}

# Validate Function
# Найти
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']); 
# добавить выше
if ($this->config->get($this->config->get('config_captcha') . '_status')) {
	$captcha = $this->load->controller('captcha/' . $this->config->get('config_captcha') . '/validate');

	if ($captcha) {
		$this->error['warning'] = $captcha;
	}
}
# 2. catalog/view/theme/ВАША ТЕМА/template/account/login.tpl

# найти
<input type="submit" value="<?php echo $button_login; ?>" class="btn btn-primary" />
# добавить ниже
<?php echo $captcha; ?>

 

В 2.0.3.1 не заработало. Ошибок нет.

Share this post


Link to post
Share on other sites
# oc 2.0.3
# 1. catalog/controller/account/login.php

# Index Function
# найти
$data['column_left'] = $this->load->controller('common/column_left');
# добавить выше
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'] = '';
}

# Validate Function
# Найти
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']); 
# добавить выше
if ($this->config->get('config_google_captcha_status') && empty($this->error['warning'])) {
	if (isset($this->request->post['g-recaptcha-response'])) {
		$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['warning'] = $this->language->get('error_captcha');
		}
	} else {
		$this->error['warning'] = $this->language->get('error_captcha');
	}
}

# 2. catalog/view/theme/ВАША ТЕМА/template/account/login.tpl

# найти
<input type="submit" value="<?php echo $button_login; ?>" class="btn btn-primary" />
# добавить ниже
<?php if ($site_key) { ?>
<div class="form-group">
  <div class="col-sm-12">
    <div class="g-recaptcha" data-sitekey="<?php echo $site_key; ?>"></div>
  </div>
</div>
<?php } ?>

 

Share this post


Link to post
Share on other sites
53 минуты назад, Designer сказал:
# oc 2.0.3
# 1. catalog/controller/account/login.php

# Index Function
# найти
$data['column_left'] = $this->load->controller('common/column_left');
# добавить выше
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'] = '';
}

# Validate Function
# Найти
$customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']); 
# добавить выше
if ($this->config->get('config_google_captcha_status') && empty($this->error['warning'])) {
	if (isset($this->request->post['g-recaptcha-response'])) {
		$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['warning'] = $this->language->get('error_captcha');
		}
	} else {
		$this->error['warning'] = $this->language->get('error_captcha');
	}
}

# 2. catalog/view/theme/ВАША ТЕМА/template/account/login.tpl

# найти
<input type="submit" value="<?php echo $button_login; ?>" class="btn btn-primary" />
# добавить ниже
<?php if ($site_key) { ?>
<div class="form-group">
  <div class="col-sm-12">
    <div class="g-recaptcha" data-sitekey="<?php echo $site_key; ?>"></div>
  </div>
</div>
<?php } ?>

 

Спасибо! Помогло. Только в 

# 2. catalog/view/theme/ВАША ТЕМА/template/account/login.tpl
добавить пришлось выше этой строчки: 
<input type="submit" value="<?php echo $button_login; ?>" class="btn btn-primary" />

А то капча вылезала за пределы раздела. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.