File tree Expand file tree Collapse file tree 5 files changed +23
-4
lines changed Expand file tree Collapse file tree 5 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public static function schema(Blueprint $table)
19
19
{
20
20
$ table ->string ('slug ' );
21
21
$ table ->string ('title ' );
22
+ $ table ->string ('password ' )->nullable ();
22
23
$ table ->longText ('content ' );
23
24
}
24
25
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ public function __invoke(string $page)
21
21
}
22
22
23
23
if ($ model = config ('pages.model ' )::find ($ page )) {
24
+ if ($ model ->password ) {
25
+ abort_unless (request ()->query ('password ' ) === $ model ->password , 403 );
26
+ }
27
+
24
28
seo ()
25
29
->title ($ model ->title )
26
30
->description (Str::limit ($ model ->content , 100 ));
Original file line number Diff line number Diff line change 77
77
->assertSee ('<meta property="og:title" content="Test page" /> ' , false )
78
78
->assertSee ('<meta property="og:description" content="This is a test page" /> ' , false );
79
79
});
80
+
81
+ test ('pages can be password-protected ' , function () {
82
+ Page::create ([
83
+ 'slug ' => 'test ' ,
84
+ 'title ' => 'Test page ' ,
85
+ 'password ' => 'foo ' ,
86
+ 'content ' => 'This is a test page '
87
+ ]);
88
+
89
+ using ($ this )->get ('/test ' )->assertForbidden ();
90
+ using ($ this )->get ('/test?password=bar ' )->assertForbidden ();
91
+ using ($ this )->get ('/test?password=foo ' )->assertSuccessful ()->assertSee ('This is a test page ' );
92
+ });
Original file line number Diff line number Diff line change 1
1
---
2
2
slug : example
3
3
title : ' Test page'
4
- updated_at : 2021-08-06T02:25:15 +00:00
5
- created_at : 2021-08-06T02:25:15 +00:00
4
+ updated_at : 2021-08-08T18:00:46 +00:00
5
+ created_at : 2021-08-08T18:00:46 +00:00
6
6
---
7
7
This is a test page
Original file line number Diff line number Diff line change 1
1
---
2
2
slug : test
3
3
title : ' Test page'
4
- updated_at : 2021-08-06T02:25:15+00:00
5
- created_at : 2021-08-06T02:25:15+00:00
4
+ password : foo
5
+ updated_at : 2021-08-08T18:00:46+00:00
6
+ created_at : 2021-08-08T18:00:46+00:00
6
7
---
7
8
This is a test page
You can’t perform that action at this time.
0 commit comments