Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
Expand All @@ -23,7 +23,7 @@ jobs:
php-version: '8.1'
extensions: mbstring, intl
coverage: none
tools: vimeo/psalm:5
tools: vimeo/psalm:6

- name: Composer Install
run: composer install
Expand Down
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://img.shields.io/github/actions/workflow/status/ctlabvn/Recaptcha/ci.yml)](https://github.com/ctlabvn/Recaptcha/actions?query=workflow%3ACI+branch%3Amaster)
[![Latest Stable Version](https://poser.pugx.org/crabstudio/recaptcha/v/stable)](https://packagist.org/packages/crabstudio/recaptcha)
[![Total Downloads](https://poser.pugx.org/crabstudio/recaptcha/downloads)](https://packagist.org/packages/crabstudio/recaptcha)
[![License](https://poser.pugx.org/crabstudio/recaptcha/license)](https://packagist.org/packages/crabstudio/recaptcha)
[![Build Status](https://img.shields.io/github/actions/workflow/status/ctlabvn/Recaptcha/ci.yml?branch=master)](https://github.com/ctlabvn/Recaptcha/actions?query=workflow%3ACI+branch%3Amaster)
[![Latest Stable Version](https://img.shields.io/packagist/v/crabstudio/recaptcha)](https://packagist.org/packages/crabstudio/recaptcha)
[![Total Downloads](https://img.shields.io/packagist/dt/crabstudio/recaptcha)](https://packagist.org/packages/crabstudio/recaptcha)
[![License](https://img.shields.io/github/license/ctlabvn/Recaptcha)](https://github.com/ctlabvn/Recaptcha/blob/master/LICENSE)

# Integrate Google Recaptcha v2 to your CakePHP project

Expand All @@ -11,27 +11,23 @@ You can install this plugin into your CakePHP application using [composer](http:

The recommended way to install composer packages is:

```
```bash
composer require crabstudio/recaptcha
```

followed by the command:

```
composer update
```

## Load plugin

From command line:
```

```bash
bin/cake plugin load Recaptcha
```

## Load Component and Configure

Override default configure from loadComponent:
```

```php
$this->loadComponent('Recaptcha.Recaptcha', [
'enable' => true, // true/false
'sitekey' => 'your_site_key', //if you don't have, get one: https://www.google.com/recaptcha/intro/index.html
Expand All @@ -44,8 +40,9 @@ $this->loadComponent('Recaptcha.Recaptcha', [
```

Override default configure from app config file:
```
file: config/app.php

```php
// file: config/app.php

/**
* Recaptcha configuration.
Expand All @@ -63,10 +60,9 @@ file: config/app.php
```

Override default configure from recaptcha config file:
```
file: config/recaptcha.php

<?php
```php
// ffile: config/recaptcha.php

return [
/**
Expand All @@ -86,8 +82,9 @@ return [
```

Load recaptcha config file:
```
file: config/bootstrap.php

```php
// file: config/bootstrap.php

Configure::load('recaptcha', 'default', true);
```
Expand All @@ -100,16 +97,19 @@ Config preference:
## Usage

Display recaptcha in your view:
```

```php
<?= $this->Form->create() ?>
<?= $this->Form->control('email') ?>
<?= $this->Recaptcha->display() ?> // Display recaptcha box in your view, if configure has enable = false, nothing will be displayed
// Display recaptcha box in your view, if configure has enable = false, nothing will be displayed
<?= $this->Recaptcha->display() ?>
<?= $this->Form->button() ?>
<?= $this->Form->end() ?>
```

Verify in your controller function
```

```php
public function forgotPassword()
{
if ($this->request->is('post')) {
Expand All @@ -121,4 +121,4 @@ Verify in your controller function
}
```

Done
Done.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cakephp/cakephp": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^10.1.0",
"phpunit/phpunit": "^10.5.5 || ^11.1.3",
"cakephp/cakephp-codesniffer": "^4.1"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
class RecaptchaComponentTest extends TestCase
{
protected Controller $controller;
protected RecaptchaComponent $Recaptcha;

public function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -43,7 +46,7 @@ public function testVerifyFalse(): void

$this->Recaptcha->expects($this->once())
->method('apiCall')
->will($this->returnValue(''));
->willReturn('');

$this->assertFalse($this->Recaptcha->verify());
}
Expand All @@ -54,7 +57,7 @@ public function testVerifyTrue(): void

$this->Recaptcha->expects($this->once())
->method('apiCall')
->will($this->returnValue('{"success":true}'));
->willReturn('{"success":true}');

$this->assertTrue($this->Recaptcha->verify());

Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/View/Helper/RecaptchaHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
class RecaptchaHelperTest extends TestCase
{
protected View $View;
protected RecaptchaHelper $Recaptcha;

public function setUp(): void
{
parent::setUp();
Expand Down