Skip to content

Commit d263838

Browse files
author
Mykolas Mankevicius
committed
Add settings
1 parent eb331f5 commit d263838

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

DynamicToken/DynamicTokenTags.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ class DynamicTokenTags extends Tags
1414
*/
1515
public function index()
1616
{
17-
$route = '/!/DynamicToken/refresh';
18-
$selector = 'form input[name="_token"]';
17+
$route = $this->actionUrl('/refresh');
18+
$selector = $this->getConfig('selector', 'form input[name="_token"]');
19+
$minutes = $this->getConfigInt('refresh_timer', 15);
20+
1921
return "
2022
<script>
2123
if (document.querySelectorAll('{$selector}').length > 0) {
@@ -55,7 +57,7 @@ function updateToken() {
5557
5658
updateToken();
5759
58-
setInterval(updateToken, 15 * 60 * 1000); // Every 15 minutes.
60+
setInterval(updateToken, {$minutes} * 60 * 1000); // Every 15 minutes.
5961
}
6062
</script>";
6163
}

DynamicToken/default.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
refresh_timer: 15
2+
selector: 'form input[name="_token"]'

DynamicToken/meta.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 'Dynamic Token'
22
version: '1.0'
3-
description: 'With {{ dynamic_token }} tag, adds dynamic crsf tokens to all forms which contain input name="_token" effectivelly providing dynamic forms in static pages'
3+
description: 'Add dynamic csrf tokens to all forms using {{ dynamic_token }} tag, in statically cached pages.'
44
developer: 'Mykolas Mankevicius'
55
developer_url: 'https://www.co-openhagen.com/'
66
commercial: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
return [
3+
'refresh_timer' => 'Refresh time',
4+
'refresh_timer_instruct' => "How often after initial load, do you want the csrf token to refresh, in minutes?",
5+
'selector' => 'CSS Selector',
6+
'selector_instruct' => "Only change this if you know what you're doing, default `form input[name=\"_token\"]`",
7+
];

DynamicToken/settings.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fields:
2+
refresh_timer:
3+
type: text
4+
validate: "required|integer"
5+
selector:
6+
type: text
7+
validate: "required"

README.MD

-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ The `{{ dynamic_token }}` inserts a bit of javascript into your static html file
2626
###### 2st:
2727
A simple controller, which checks the refferer and if the refferer matches your `APP_URL` it returns a fresh `csrf` token.
2828

29-
### Gotchas
30-
If you've changed your api denominator, you will need to modify `$route = '/!/DynamicToken/refresh';` in the `DynamicToken/DynamicTokenTags.php` file. The default statamic denominator is `/!/`;
31-
3229
### Upcoming
33-
- Settings: set refresh time span, currently 15 minutes
34-
- Automatic pickup of your api denominator
3530
- Server only handling of forms, without the `{{ dynamic_token }}` tag
3631

3732
### Contact

0 commit comments

Comments
 (0)