Skip to content

Commit

Permalink
Merge branch 'release/1.1.0' into craft-3
Browse files Browse the repository at this point in the history
  • Loading branch information
JodebaDigitalPulse committed Apr 25, 2023
2 parents 788de51 + 96946a7 commit 99a2e57
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.1.0 - 2023-04-25
### Added
- setting to add custom endpoint (self hosted lite)
- offline js files: widget script version 0.9.11

## 1.0.4 - 2023-02-14
### Fix
- fixes error when using EU endpoint: unknown property: digitalpulsebe\friendlycaptcha\services\ValidateService::endpoint
Expand Down
1 change: 1 addition & 0 deletions src/assets/js/widget.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/assets/js/widget.module.min.js

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class Settings extends Model
*/
public string $endpoint = 'global';

/**
* base url for custom servers
* @var string|null $customEndpoint
*/
public ?string $customEndpoint = null;

/**
* @var bool
*/
Expand All @@ -74,6 +80,18 @@ public function getApiKey(): string
return App::parseEnv($this->apiKey);
}

/**
* @return ?string
*/
public function getCustomEndpoint(): ?string
{
if ($this->customEndpoint) {
return App::parseEnv($this->customEndpoint);
}

return null;
}

public function behaviors(): array
{
return [
Expand All @@ -91,7 +109,7 @@ public function rules()
['apiKey', 'string'],
['darkMode', 'boolean'],
['startEvent', 'in', 'range' => ['auto', 'focus', 'none']],
['endpoint', 'in', 'range' => ['global', 'eu']],
['endpoint', 'in', 'range' => ['global', 'eu', 'custom']],
[['siteKey', 'apiKey', 'startEvent', 'endpoint'], 'required'],
['validateContactForm', 'boolean'],
['validateUsersRegistration', 'boolean'],
Expand Down
12 changes: 10 additions & 2 deletions src/services/ValidateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ protected function getSiteKey(): string

public function getEndpointUrl(string $endpoint, string $service): string
{
if ($endpoint == 'custom') {
$baseUrl = FriendlyCaptcha::$plugin->getSettings()->getCustomEndpoint();
if (substr($baseUrl, -1) !== '/') {
// append trailing slash if needed
$baseUrl = $baseUrl.'/';
}
return $baseUrl.$service;
}
if (!isset($this->endpoints[$endpoint])) {
throw new Exception('Unsupported Friendly Captcha endpoint');
}
Expand All @@ -142,8 +150,8 @@ public function renderWidget(array $attributes = []): Markup
{
$settings = FriendlyCaptcha::$plugin->getSettings();

Craft::$app->view->registerJsFile('https://unpkg.com/[email protected]/widget.module.min.js', ['async' => true, 'defer' => true]);
Craft::$app->view->registerJsFile('https://unpkg.com/[email protected]/widget.min.js', ['async' => true, 'defer' => true]);
Craft::$app->view->registerJsFile(Craft::$app->assetManager->getPublishedUrl('@digitalpulsebe/friendlycaptcha/assets/js/widget.module.min.js', true), ['async' => true, 'defer' => true]);
Craft::$app->view->registerJsFile(Craft::$app->assetManager->getPublishedUrl('@digitalpulsebe/friendlycaptcha/assets/js/widget.min.js', true), ['async' => true, 'defer' => true]);

$defaultAttributes = [
'class' => 'frc-captcha',
Expand Down
25 changes: 23 additions & 2 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@
}, {
value: 'eu',
label: 'EU (Friendly Captcha Advanced or Enterprise plan)',
}, {
value: 'custom',
label: 'Custom (Self Hosted Captcha Server)',
}],
errors: settings.getErrors('endpoint')
errors: settings.getErrors('endpoint'),
toggle: true
}) }}
<p class="notice has-icon">
<span class="icon" aria-hidden="true"></span>
Expand All @@ -116,4 +120,21 @@
Friendly Captcha documentation about Dedicated EU Endpoint
</a>
</span>
</p>
</p>


<div id="custom"{% if settings.endpoint != 'custom' %} class="hidden"{% endif %}>
<div id="endpoint-custom-fields">
{{ forms.autosuggestField({
label: "Custom endpoint",
instructions: "Use a custom endpoint for the Self Hosted Captcha Server",
id: 'customEndpoint',
name: 'customEndpoint',
value: settings.customEndpoint,
required: false,
suggestEnvVars: true,
errors: settings.getErrors('customEndpoint')
})
}}
</div>
</div>

0 comments on commit 99a2e57

Please sign in to comment.