Last active
March 10, 2017 07:53
-
-
Save anhtuank7c/6fce573e6655da98c616 to your computer and use it in GitHub Desktop.
Google Recaptcha ref: http://qiita.com/anhtuank7c/items/6edb2b332d79136192e1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer require crabstudio/recaptcha |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"require": { | |
"crabstudio/recaptcha": "^1.0" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function forgotPassword() { | |
if($this->request->is('post')){ | |
if($this->Recaptcha->verify()) { // if configure enable = false, always return true | |
//do something here | |
} | |
$this->Flash->error(__('Please pass Google Recaptcha first')); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$config = [ | |
'Recaptcha' => [ | |
'sitekey' => 'the site key', | |
'secret' => 'the secret', | |
'theme' => 'light', | |
'type' => 'image', | |
'enable' => true | |
] | |
]; | |
Cake\Core\Configure::config('default', $config); | |
Cake\Core\Configure::load('recaptcha', 'default', false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function initialize() { | |
parent::initialize(); | |
if ($this->request->action === 'contact') { | |
$this->loadComponent('Crabstudio/Recaptcha.Recaptcha'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function contact() { | |
if ($this->request->is('post')) { | |
if ($this->Recaptcha->verify()) { | |
if ($contact->execute($this->request->data)) { | |
$this->Flash->success(__('We will get back to you soon.')); | |
return $this->redirect($this->referer()); | |
} else { | |
$this->Flash->error(__('There was a problem submitting your form.')); | |
} | |
} else { | |
$this->Flash->error(__('Please check your Recaptcha Box.')); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?= $this->Form->create() ?> | |
<?= $this->Recaptcha->display() ?> | |
<?= $this->Form->input('name', [ | |
'label' => __('Your Name'), | |
// 'default' => $this->request->query('name'); // in case you add the Prg Component | |
]) ?> | |
<?= $this->Form->input('message', [ | |
'type' => 'textarea', | |
// 'default' => $this->request->query('message'); // in case you add the Prg Component | |
'label' => __('Your Message') | |
]) ?> | |
<?= $this->Form->button(__('OK')) ?> | |
<?= $this->Form->end() ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment