Skip to content

Commit b75e52c

Browse files
committed
Add password protection preset
1 parent c037d1b commit b75e52c

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
return [
4+
'handle' => 'password_protection',
5+
'name' => 'Password protection',
6+
'description' => 'Protect pages with a password.',
7+
'operations' => [
8+
[
9+
'type' => 'copy',
10+
'input' => 'resources/views/page_builder/_login.antlers.html',
11+
'output' => 'resources/views/page_builder/_login.antlers.html',
12+
],
13+
[
14+
'type' => 'copy',
15+
'input' => 'content/collections/pages/login.md',
16+
'output' => 'content/collections/pages/login.md',
17+
],
18+
[
19+
'type' => 'copy',
20+
'input' => 'resources/fieldsets/login.yaml',
21+
'output' => 'resources/fieldsets/login.yaml',
22+
],
23+
[
24+
'type' => 'copy',
25+
'input' => 'resources/fieldsets/protect.yaml',
26+
'output' => 'resources/fieldsets/protect.yaml',
27+
],
28+
[
29+
'type' => 'update_page_builder',
30+
'block' => [
31+
'name' => 'Login',
32+
'instructions' => 'The protection login form.',
33+
'icon' => 'login-key-2',
34+
'handle' => 'login',
35+
],
36+
],
37+
[
38+
'type' => 'notify',
39+
'content' => "Add this to your `routes/web.php` file:\n\nuse Illuminate\Http\Request;\nuse Illuminate\Support\Facades\Route;\nuse Statamic\Facades\GlobalSet;\nuse Statamic\Facades\Entry;\n\nRoute::get('/protection-form-url', function (Request \$request) {\n\treturn redirect(Entry::find(GlobalSet::findByHandle('configuration')->inDefaultSite()->get('login_entry'))->url() . '?token=' . \$request->token);\n});",
40+
],
41+
[
42+
'type' => 'notify',
43+
'content' => "Update the `password` array in `config/statamic/protect.php` with the following:\n\n'password' => [\n\t'driver' => 'password',\n\t'allowed' => [],\n\t'field' => 'password',\n\t'form_url' => 'protection-form-url',\n],",
44+
],
45+
[
46+
'type' => 'notify',
47+
'content' => "Add the following field to a global like `resources/blueprints/globals/configruation.yaml`:\n\n-\n\thandle: login_entry\n\tfield: common.entry\n\tconfig:\n\t\tdisplay: Login\n\t\twidth: 50\n\t\tinstructions: 'The login page.'\n\t\tcollections:\n\t\t\t- pages\n\t\tvalidate:\n\t\t\t- required",
48+
],
49+
[
50+
'type' => 'notify',
51+
'content' => "Add the following section to the blueprints you want to potect, like `resources/blueprints/collections/pages/page.yaml`:\n\n-\n\tdisplay: 'Protect'\n\tfields:\n\t\t-\n\t\t\timport: protect",
52+
],
53+
[
54+
'type' => 'notify',
55+
'content' => "Add this to your `lang/locale/strings.php` file:\n\n'password' => 'Password',\n'password_invalid' => 'Password invalid.',\n'password_login' => 'Login',",
56+
],
57+
],
58+
];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
id: 2f6436c7-36cd-4863-9288-8ffa28528d7a
3+
blueprint: page
4+
title: Login
5+
seo_noindex: true
6+
seo_nofollow: false
7+
seo_canonical_type: entry
8+
sitemap_change_frequency: weekly
9+
sitemap_priority: 0.5
10+
protect_entry: false
11+
page_builder:
12+
-
13+
id: m6ulso0w
14+
type: login
15+
enabled: true
16+
---
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: Login
2+
fields: []
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
title: Login
2+
fields:
3+
-
4+
handle: protect_entry
5+
field:
6+
type: toggle
7+
display: Protect
8+
instructions: 'Optionally protect this page with a password.'
9+
instructions_position: below
10+
listable: true
11+
-
12+
handle: protect
13+
field:
14+
default: password
15+
type: hidden
16+
display: Protect
17+
if:
18+
protect_entry: 'equals true'
19+
-
20+
handle: password
21+
field:
22+
type: text
23+
display: Password
24+
instructions: 'Protect this page with password.'
25+
instructions_position: below
26+
validate:
27+
- sometimes
28+
- required
29+
if:
30+
protect_entry: 'equals true'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{#
2+
@name Login
3+
@desc The Login page builder block.
4+
@set page.page_builder.login
5+
#}}
6+
7+
<!-- /page_builder/_login.antlers.html -->
8+
{{ partial:page_builder/block }}
9+
<div class="span-content md:col-start-[col-5] md:col-span-4">
10+
{{ protect:password_form }}
11+
{{ if no_token }}
12+
{{ 404 }}
13+
{{ else }}
14+
<div class="flex flex-col stack-4">
15+
<div class="flex flex-col stack-1">
16+
<label class="font-bold" for="password">
17+
{{ trans:strings.password }}
18+
</label>
19+
20+
<input type="password" id="password" name="password" class="w-full border-neutral focus:border-primary rounded-sm caret-primary" />
21+
22+
{{ errors:password }}
23+
<span class="mt-1 text-red-700 text-sm font-bold">{{ trans:strings.password_invalid }}</span>
24+
{{ /errors:password }}
25+
</div>
26+
27+
{{ partial:components/button as="button" button_type="button" class="self-end" label="{ trans:strings.password_login }" }}
28+
</div>
29+
{{ /if }}
30+
{{ /protect:password_form }}
31+
</div>
32+
{{ /partial:page_builder/block }}
33+
<!-- End: /page_builder/_login.antlers.html -->

0 commit comments

Comments
 (0)