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)
1919 {
2020 $ table ->string ('slug ' );
2121 $ table ->string ('title ' );
22+ $ table ->string ('password ' )->nullable ();
2223 $ table ->longText ('content ' );
2324 }
2425
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ public function __invoke(string $page)
2121 }
2222
2323 if ($ model = config ('pages.model ' )::find ($ page )) {
24+ if ($ model ->password ) {
25+ abort_unless (request ()->query ('password ' ) === $ model ->password , 403 );
26+ }
27+
2428 seo ()
2529 ->title ($ model ->title )
2630 ->description (Str::limit ($ model ->content , 100 ));
Original file line number Diff line number Diff line change 7777 ->assertSee ('<meta property="og:title" content="Test page" /> ' , false )
7878 ->assertSee ('<meta property="og:description" content="This is a test page" /> ' , false );
7979});
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 11---
22slug : example
33title : ' 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
66---
77This is a test page
Original file line number Diff line number Diff line change 11---
22slug : test
33title : ' 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
67---
78This is a test page
You can’t perform that action at this time.
0 commit comments