mirror of
https://github.com/archtechx/laravel-pages.git
synced 2025-12-12 01:44:03 +00:00
Add password protected pages (resolve #3)
This commit is contained in:
parent
e9d1cd6fe7
commit
c0c4ebe0d0
5 changed files with 23 additions and 4 deletions
|
|
@ -19,6 +19,7 @@ class Page extends Model
|
||||||
{
|
{
|
||||||
$table->string('slug');
|
$table->string('slug');
|
||||||
$table->string('title');
|
$table->string('title');
|
||||||
|
$table->string('password')->nullable();
|
||||||
$table->longText('content');
|
$table->longText('content');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ class PageController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($model = config('pages.model')::find($page)) {
|
if ($model = config('pages.model')::find($page)) {
|
||||||
|
if ($model->password) {
|
||||||
|
abort_unless(request()->query('password') === $model->password, 403);
|
||||||
|
}
|
||||||
|
|
||||||
seo()
|
seo()
|
||||||
->title($model->title)
|
->title($model->title)
|
||||||
->description(Str::limit($model->content, 100));
|
->description(Str::limit($model->content, 100));
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,16 @@ test('SEO metadata is set on markdown pages', function () {
|
||||||
->assertSee('<meta property="og:title" content="Test page" />', false)
|
->assertSee('<meta property="og:title" content="Test page" />', false)
|
||||||
->assertSee('<meta property="og:description" content="This is a test page" />', false);
|
->assertSee('<meta property="og:description" content="This is a test page" />', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('pages can be password-protected', function () {
|
||||||
|
Page::create([
|
||||||
|
'slug' => 'test',
|
||||||
|
'title' => 'Test page',
|
||||||
|
'password' => 'foo',
|
||||||
|
'content' => 'This is a test page'
|
||||||
|
]);
|
||||||
|
|
||||||
|
using($this)->get('/test')->assertForbidden();
|
||||||
|
using($this)->get('/test?password=bar')->assertForbidden();
|
||||||
|
using($this)->get('/test?password=foo')->assertSuccessful()->assertSee('This is a test page');
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
slug: example
|
slug: example
|
||||||
title: 'Test page'
|
title: 'Test page'
|
||||||
updated_at: 2021-08-06T02:25:15+00:00
|
updated_at: 2021-08-08T18:00:46+00:00
|
||||||
created_at: 2021-08-06T02:25:15+00:00
|
created_at: 2021-08-08T18:00:46+00:00
|
||||||
---
|
---
|
||||||
This is a test page
|
This is a test page
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
---
|
---
|
||||||
slug: test
|
slug: test
|
||||||
title: 'Test page'
|
title: 'Test page'
|
||||||
updated_at: 2021-08-06T02:25:15+00:00
|
password: foo
|
||||||
created_at: 2021-08-06T02:25:15+00:00
|
updated_at: 2021-08-08T18:00:46+00:00
|
||||||
|
created_at: 2021-08-08T18:00:46+00:00
|
||||||
---
|
---
|
||||||
This is a test page
|
This is a test page
|
||||||
Loading…
Add table
Add a link
Reference in a new issue