first version
This commit is contained in:
25
kirby/config/api/authentication.php
Executable file
25
kirby/config/api/authentication.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Auth;
|
||||
use Kirby\Exception\PermissionException;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
return function () {
|
||||
$auth = $this->kirby()->auth();
|
||||
|
||||
// csrf token check
|
||||
if ($auth->type() === 'session' && $auth->csrf() === false) {
|
||||
throw new PermissionException('Unauthenticated', 403);
|
||||
}
|
||||
|
||||
// get user from session or basic auth
|
||||
if ($user = $auth->user()) {
|
||||
if ($user->role()->permissions()->for('access', 'panel') === false) {
|
||||
throw new PermissionException(['key' => 'access.panel']);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
throw new PermissionException('Unauthenticated', 403);
|
||||
};
|
80
kirby/config/api/collections.php
Executable file
80
kirby/config/api/collections.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Files;
|
||||
use Kirby\Cms\Languages;
|
||||
use Kirby\Cms\Pages;
|
||||
use Kirby\Cms\Roles;
|
||||
use Kirby\Cms\Translations;
|
||||
use Kirby\Cms\Users;
|
||||
|
||||
/**
|
||||
* Api Collection Definitions
|
||||
*/
|
||||
return [
|
||||
|
||||
/**
|
||||
* Children
|
||||
*/
|
||||
'children' => [
|
||||
'model' => 'page',
|
||||
'type' => Pages::class,
|
||||
'view' => 'compact'
|
||||
],
|
||||
|
||||
/**
|
||||
* Files
|
||||
*/
|
||||
'files' => [
|
||||
'model' => 'file',
|
||||
'type' => Files::class
|
||||
],
|
||||
|
||||
/**
|
||||
* Languages
|
||||
*/
|
||||
'languages' => [
|
||||
'model' => 'language',
|
||||
'type' => Languages::class,
|
||||
'view' => 'compact'
|
||||
],
|
||||
|
||||
/**
|
||||
* Pages
|
||||
*/
|
||||
'pages' => [
|
||||
'model' => 'page',
|
||||
'type' => Pages::class,
|
||||
'view' => 'compact'
|
||||
],
|
||||
|
||||
/**
|
||||
* Roles
|
||||
*/
|
||||
'roles' => [
|
||||
'model' => 'role',
|
||||
'type' => Roles::class,
|
||||
'view' => 'compact'
|
||||
],
|
||||
|
||||
/**
|
||||
* Translations
|
||||
*/
|
||||
'translations' => [
|
||||
'model' => 'translation',
|
||||
'type' => Translations::class,
|
||||
'view' => 'compact'
|
||||
],
|
||||
|
||||
/**
|
||||
* Users
|
||||
*/
|
||||
'users' => [
|
||||
'default' => function () {
|
||||
return $this->users();
|
||||
},
|
||||
'model' => 'user',
|
||||
'type' => Users::class,
|
||||
'view' => 'compact'
|
||||
]
|
||||
|
||||
];
|
24
kirby/config/api/models.php
Executable file
24
kirby/config/api/models.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Cms\Site;
|
||||
|
||||
/**
|
||||
* Api Model Definitions
|
||||
*/
|
||||
return [
|
||||
'File' => include __DIR__ . '/models/File.php',
|
||||
'FileBlueprint' => include __DIR__ . '/models/FileBlueprint.php',
|
||||
'FileVersion' => include __DIR__ . '/models/FileVersion.php',
|
||||
'Language' => include __DIR__ . '/models/Language.php',
|
||||
'Page' => include __DIR__ . '/models/Page.php',
|
||||
'PageBlueprint' => include __DIR__ . '/models/PageBlueprint.php',
|
||||
'Role' => include __DIR__ . '/models/Role.php',
|
||||
'Site' => include __DIR__ . '/models/Site.php',
|
||||
'SiteBlueprint' => include __DIR__ . '/models/SiteBlueprint.php',
|
||||
'System' => include __DIR__ . '/models/System.php',
|
||||
'Translation' => include __DIR__ . '/models/Translation.php',
|
||||
'User' => include __DIR__ . '/models/User.php',
|
||||
'UserBlueprint' => include __DIR__ . '/models/UserBlueprint.php',
|
||||
];
|
160
kirby/config/api/models/File.php
Executable file
160
kirby/config/api/models/File.php
Executable file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\File;
|
||||
use Kirby\Cms\Form;
|
||||
|
||||
/**
|
||||
* File
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'blueprint' => function (File $file) {
|
||||
return $file->blueprint();
|
||||
},
|
||||
'content' => function (File $file) {
|
||||
return Form::for($file)->values();
|
||||
},
|
||||
'dimensions' => function (File $file) {
|
||||
return $file->dimensions()->toArray();
|
||||
},
|
||||
'exists' => function (File $file) {
|
||||
return $file->exists();
|
||||
},
|
||||
'extension' => function (File $file) {
|
||||
return $file->extension();
|
||||
},
|
||||
'filename' => function (File $file) {
|
||||
return $file->filename();
|
||||
},
|
||||
'id' => function (File $file) {
|
||||
return $file->id();
|
||||
},
|
||||
'link' => function (File $file) {
|
||||
return $file->panelUrl(true);
|
||||
},
|
||||
'mime' => function (File $file) {
|
||||
return $file->mime();
|
||||
},
|
||||
'modified' => function (File $file) {
|
||||
return $file->modified('c');
|
||||
},
|
||||
'name' => function (File $file) {
|
||||
return $file->name();
|
||||
},
|
||||
'next' => function (File $file) {
|
||||
return $file->next();
|
||||
},
|
||||
'nextWithTemplate' => function (File $file) {
|
||||
$files = $file->templateSiblings()->sortBy('sort', 'asc');
|
||||
$index = $files->indexOf($file);
|
||||
|
||||
return $files->nth($index + 1);
|
||||
},
|
||||
'options' => function (File $file) {
|
||||
return $file->permissions()->toArray();
|
||||
},
|
||||
'prev' => function (File $file) {
|
||||
return $file->prev();
|
||||
},
|
||||
'prevWithTemplate' => function (File $file) {
|
||||
$files = $file->templateSiblings()->sortBy('sort', 'asc');
|
||||
$index = $files->indexOf($file);
|
||||
|
||||
return $files->nth($index - 1);
|
||||
},
|
||||
'niceSize' => function (File $file) {
|
||||
return $file->niceSize();
|
||||
},
|
||||
'panelIcon' => function (File $file) {
|
||||
return $file->panelIcon();
|
||||
},
|
||||
'panelImage' => function (File $file) {
|
||||
return $file->panelImage();
|
||||
},
|
||||
'parent' => function (File $file) {
|
||||
return $file->parent();
|
||||
},
|
||||
'parents' => function (File $file) {
|
||||
return $file->parents()->flip();
|
||||
},
|
||||
'template' => function (File $file) {
|
||||
return $file->template();
|
||||
},
|
||||
'size' => function (File $file) {
|
||||
return $file->size();
|
||||
},
|
||||
'thumbs' => function ($file) {
|
||||
if ($file->isResizable() === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'tiny' => $file->resize(128)->url(),
|
||||
'small' => $file->resize(256)->url(),
|
||||
'medium' => $file->resize(512)->url(),
|
||||
'large' => $file->resize(768)->url(),
|
||||
'huge' => $file->resize(1024)->url(),
|
||||
];
|
||||
},
|
||||
'type' => function (File $file) {
|
||||
return $file->type();
|
||||
},
|
||||
'url' => function (File $file) {
|
||||
return $file->url(true);
|
||||
},
|
||||
],
|
||||
'type' => File::class,
|
||||
'views' => [
|
||||
'default' => [
|
||||
'content',
|
||||
'dimensions',
|
||||
'exists',
|
||||
'extension',
|
||||
'filename',
|
||||
'id',
|
||||
'link',
|
||||
'mime',
|
||||
'modified',
|
||||
'name',
|
||||
'next' => 'compact',
|
||||
'niceSize',
|
||||
'parent' => 'compact',
|
||||
'options',
|
||||
'prev' => 'compact',
|
||||
'size',
|
||||
'template',
|
||||
'type',
|
||||
'url'
|
||||
],
|
||||
'compact' => [
|
||||
'filename',
|
||||
'id',
|
||||
'link',
|
||||
'type',
|
||||
'url',
|
||||
],
|
||||
'panel' => [
|
||||
'blueprint',
|
||||
'content',
|
||||
'dimensions',
|
||||
'extension',
|
||||
'filename',
|
||||
'id',
|
||||
'link',
|
||||
'mime',
|
||||
'modified',
|
||||
'name',
|
||||
'nextWithTemplate' => 'compact',
|
||||
'niceSize',
|
||||
'options',
|
||||
'panelIcon',
|
||||
'panelImage',
|
||||
'parent' => 'compact',
|
||||
'parents' => ['id', 'slug', 'title'],
|
||||
'prevWithTemplate' => 'compact',
|
||||
'template',
|
||||
'type',
|
||||
'url'
|
||||
]
|
||||
],
|
||||
];
|
26
kirby/config/api/models/FileBlueprint.php
Executable file
26
kirby/config/api/models/FileBlueprint.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\FileBlueprint;
|
||||
|
||||
/**
|
||||
* FileBlueprint
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'name' => function (FileBlueprint $blueprint) {
|
||||
return $blueprint->name();
|
||||
},
|
||||
'options' => function (FileBlueprint $blueprint) {
|
||||
return $blueprint->options();
|
||||
},
|
||||
'tabs' => function (FileBlueprint $blueprint) {
|
||||
return $blueprint->tabs();
|
||||
},
|
||||
'title' => function (FileBlueprint $blueprint) {
|
||||
return $blueprint->title();
|
||||
},
|
||||
],
|
||||
'type' => FileBlueprint::class,
|
||||
'views' => [
|
||||
],
|
||||
];
|
83
kirby/config/api/models/FileVersion.php
Executable file
83
kirby/config/api/models/FileVersion.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\FileVersion;
|
||||
|
||||
/**
|
||||
* FileVersion
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'dimensions' => function (FileVersion $file) {
|
||||
return $file->dimensions()->toArray();
|
||||
},
|
||||
'exists' => function (FileVersion $file) {
|
||||
return $file->exists();
|
||||
},
|
||||
'extension' => function (FileVersion $file) {
|
||||
return $file->extension();
|
||||
},
|
||||
'filename' => function (FileVersion $file) {
|
||||
return $file->filename();
|
||||
},
|
||||
'id' => function (FileVersion $file) {
|
||||
return $file->id();
|
||||
},
|
||||
'mime' => function (FileVersion $file) {
|
||||
return $file->mime();
|
||||
},
|
||||
'modified' => function (FileVersion $file) {
|
||||
return $file->modified('c');
|
||||
},
|
||||
'name' => function (FileVersion $file) {
|
||||
return $file->name();
|
||||
},
|
||||
'niceSize' => function (FileVersion $file) {
|
||||
return $file->niceSize();
|
||||
},
|
||||
'size' => function (FileVersion $file) {
|
||||
return $file->size();
|
||||
},
|
||||
'type' => function (FileVersion $file) {
|
||||
return $file->type();
|
||||
},
|
||||
'url' => function (FileVersion $file) {
|
||||
return $file->url(true);
|
||||
},
|
||||
],
|
||||
'type' => FileVersion::class,
|
||||
'views' => [
|
||||
'default' => [
|
||||
'dimensions',
|
||||
'exists',
|
||||
'extension',
|
||||
'filename',
|
||||
'id',
|
||||
'mime',
|
||||
'modified',
|
||||
'name',
|
||||
'niceSize',
|
||||
'size',
|
||||
'type',
|
||||
'url'
|
||||
],
|
||||
'compact' => [
|
||||
'filename',
|
||||
'id',
|
||||
'type',
|
||||
'url',
|
||||
],
|
||||
'panel' => [
|
||||
'dimensions',
|
||||
'extension',
|
||||
'filename',
|
||||
'id',
|
||||
'mime',
|
||||
'modified',
|
||||
'name',
|
||||
'niceSize',
|
||||
'template',
|
||||
'type',
|
||||
'url'
|
||||
]
|
||||
],
|
||||
];
|
37
kirby/config/api/models/Language.php
Executable file
37
kirby/config/api/models/Language.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Language;
|
||||
|
||||
/**
|
||||
* Language
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'code' => function (Language $language) {
|
||||
return $language->code();
|
||||
},
|
||||
'default' => function (Language $language) {
|
||||
return $language->isDefault();
|
||||
},
|
||||
'direction' => function (Language $language) {
|
||||
return $language->direction();
|
||||
},
|
||||
'locale' => function (Language $language) {
|
||||
return $language->locale();
|
||||
},
|
||||
'name' => function (Language $language) {
|
||||
return $language->name();
|
||||
},
|
||||
'url' => function (Language $language) {
|
||||
return $language->url();
|
||||
},
|
||||
],
|
||||
'type' => Language::class,
|
||||
'views' => [
|
||||
'compact' => [
|
||||
'code',
|
||||
'default',
|
||||
'name',
|
||||
]
|
||||
]
|
||||
];
|
155
kirby/config/api/models/Page.php
Executable file
155
kirby/config/api/models/Page.php
Executable file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Form;
|
||||
use Kirby\Cms\Page;
|
||||
|
||||
/**
|
||||
* Page
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'blueprint' => function (Page $page) {
|
||||
return $page->blueprint();
|
||||
},
|
||||
'blueprints' => function (Page $page) {
|
||||
return $page->blueprints();
|
||||
},
|
||||
'children' => function (Page $page) {
|
||||
return $page->children();
|
||||
},
|
||||
'content' => function (Page $page) {
|
||||
return Form::for($page)->values();
|
||||
},
|
||||
'drafts' => function (Page $page) {
|
||||
return $page->drafts();
|
||||
},
|
||||
'errors' => function (Page $page) {
|
||||
return $page->errors();
|
||||
},
|
||||
'files' => function (Page $page) {
|
||||
return $page->files();
|
||||
},
|
||||
'hasChildren' => function (Page $page) {
|
||||
return $page->hasChildren();
|
||||
},
|
||||
'hasDrafts' => function (Page $page) {
|
||||
return $page->hasDrafts();
|
||||
},
|
||||
'id' => function (Page $page) {
|
||||
return $page->id();
|
||||
},
|
||||
'isSortable' => function (Page $page) {
|
||||
return $page->isSortable();
|
||||
},
|
||||
'next' => function (Page $page) {
|
||||
return $page
|
||||
->nextAll()
|
||||
->filterBy('intendedTemplate', $page->intendedTemplate())
|
||||
->filterBy('status', $page->status())
|
||||
->filterBy('isReadable', true)
|
||||
->first();
|
||||
},
|
||||
'num' => function (Page $page) {
|
||||
return $page->num();
|
||||
},
|
||||
'options' => function (Page $page) {
|
||||
return $page->permissions()->toArray();
|
||||
},
|
||||
'panelIcon' => function (Page $page) {
|
||||
return $page->panelIcon();
|
||||
},
|
||||
'panelImage' => function (Page $page) {
|
||||
return $page->panelImage();
|
||||
},
|
||||
'parent' => function (Page $page) {
|
||||
return $page->parent();
|
||||
},
|
||||
'parents' => function (Page $page) {
|
||||
return $page->parents()->flip();
|
||||
},
|
||||
'prev' => function (Page $page) {
|
||||
return $page
|
||||
->prevAll()
|
||||
->filterBy('intendedTemplate', $page->intendedTemplate())
|
||||
->filterBy('status', $page->status())
|
||||
->filterBy('isReadable', true)
|
||||
->last();
|
||||
},
|
||||
'previewUrl' => function (Page $page) {
|
||||
return $page->previewUrl();
|
||||
},
|
||||
'siblings' => function (Page $page) {
|
||||
if ($page->isDraft() === true) {
|
||||
return $page->parentModel()->children()->not($page);
|
||||
} else {
|
||||
return $page->siblings();
|
||||
}
|
||||
},
|
||||
'slug' => function (Page $page) {
|
||||
return $page->slug();
|
||||
},
|
||||
'status' => function (Page $page) {
|
||||
return $page->status();
|
||||
},
|
||||
'template' => function (Page $page) {
|
||||
return $page->intendedTemplate()->name();
|
||||
},
|
||||
'title' => function (Page $page) {
|
||||
return $page->title()->value();
|
||||
},
|
||||
'url' => function (Page $page) {
|
||||
return $page->url();
|
||||
},
|
||||
],
|
||||
'type' => Page::class,
|
||||
'views' => [
|
||||
'compact' => [
|
||||
'id',
|
||||
'title',
|
||||
'url',
|
||||
'num'
|
||||
],
|
||||
'default' => [
|
||||
'content',
|
||||
'id',
|
||||
'status',
|
||||
'num',
|
||||
'options',
|
||||
'parent' => 'compact',
|
||||
'slug',
|
||||
'template',
|
||||
'title',
|
||||
'url'
|
||||
],
|
||||
'panel' => [
|
||||
'id',
|
||||
'blueprint',
|
||||
'content',
|
||||
'errors',
|
||||
'status',
|
||||
'options',
|
||||
'next' => ['id', 'slug', 'title'],
|
||||
'parents' => ['id', 'slug', 'title'],
|
||||
'prev' => ['id', 'slug', 'title'],
|
||||
'previewUrl',
|
||||
'slug',
|
||||
'title',
|
||||
'url'
|
||||
],
|
||||
'selector' => [
|
||||
'id',
|
||||
'title',
|
||||
'parent' => [
|
||||
'id',
|
||||
'title'
|
||||
],
|
||||
'children' => [
|
||||
'hasChildren',
|
||||
'id',
|
||||
'panelIcon',
|
||||
'panelImage',
|
||||
'title',
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
35
kirby/config/api/models/PageBlueprint.php
Executable file
35
kirby/config/api/models/PageBlueprint.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\PageBlueprint;
|
||||
|
||||
/**
|
||||
* PageBlueprint
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'name' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->name();
|
||||
},
|
||||
'num' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->num();
|
||||
},
|
||||
'options' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->options();
|
||||
},
|
||||
'preview' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->preview();
|
||||
},
|
||||
'status' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->status();
|
||||
},
|
||||
'tabs' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->tabs();
|
||||
},
|
||||
'title' => function (PageBlueprint $blueprint) {
|
||||
return $blueprint->title();
|
||||
},
|
||||
],
|
||||
'type' => PageBlueprint::class,
|
||||
'views' => [
|
||||
],
|
||||
];
|
31
kirby/config/api/models/Role.php
Executable file
31
kirby/config/api/models/Role.php
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Role;
|
||||
|
||||
/**
|
||||
* Role
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'description' => function (Role $role) {
|
||||
return $role->description();
|
||||
},
|
||||
'name' => function (Role $role) {
|
||||
return $role->name();
|
||||
},
|
||||
'permissions' => function (Role $role) {
|
||||
return $role->permissions()->toArray();
|
||||
},
|
||||
'title' => function (Role $role) {
|
||||
return $role->title();
|
||||
},
|
||||
],
|
||||
'type' => Role::class,
|
||||
'views' => [
|
||||
'compact' => [
|
||||
'description',
|
||||
'name',
|
||||
'title'
|
||||
]
|
||||
]
|
||||
];
|
65
kirby/config/api/models/Site.php
Executable file
65
kirby/config/api/models/Site.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Form;
|
||||
use Kirby\Cms\Site;
|
||||
|
||||
/**
|
||||
* Site
|
||||
*/
|
||||
return [
|
||||
'default' => function () {
|
||||
return $this->site();
|
||||
},
|
||||
'fields' => [
|
||||
'blueprint' => function (Site $site) {
|
||||
return $site->blueprint();
|
||||
},
|
||||
'children' => function (Site $site) {
|
||||
return $site->children();
|
||||
},
|
||||
'content' => function (Site $site) {
|
||||
return Form::for($site)->values();
|
||||
},
|
||||
'files' => function (Site $site) {
|
||||
return $site->files();
|
||||
},
|
||||
'options' => function (Site $site) {
|
||||
return $site->permissions()->toArray();
|
||||
},
|
||||
'title' => function (Site $site) {
|
||||
return $site->title()->value();
|
||||
},
|
||||
'url' => function (Site $site) {
|
||||
return $site->url();
|
||||
},
|
||||
],
|
||||
'type' => Site::class,
|
||||
'views' => [
|
||||
'compact' => [
|
||||
'title',
|
||||
'url'
|
||||
],
|
||||
'default' => [
|
||||
'content',
|
||||
'options',
|
||||
'title',
|
||||
'url'
|
||||
],
|
||||
'panel' => [
|
||||
'title',
|
||||
'blueprint',
|
||||
'content',
|
||||
'options',
|
||||
'url'
|
||||
],
|
||||
'selector' => [
|
||||
'title',
|
||||
'children' => [
|
||||
'id',
|
||||
'title',
|
||||
'panelIcon',
|
||||
'hasChildren'
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
26
kirby/config/api/models/SiteBlueprint.php
Executable file
26
kirby/config/api/models/SiteBlueprint.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\SiteBlueprint;
|
||||
|
||||
/**
|
||||
* SiteBlueprint
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'name' => function (SiteBlueprint $blueprint) {
|
||||
return $blueprint->name();
|
||||
},
|
||||
'options' => function (SiteBlueprint $blueprint) {
|
||||
return $blueprint->options();
|
||||
},
|
||||
'tabs' => function (SiteBlueprint $blueprint) {
|
||||
return $blueprint->tabs();
|
||||
},
|
||||
'title' => function (SiteBlueprint $blueprint) {
|
||||
return $blueprint->title();
|
||||
},
|
||||
],
|
||||
'type' => SiteBlueprint::class,
|
||||
'views' => [
|
||||
],
|
||||
];
|
95
kirby/config/api/models/System.php
Executable file
95
kirby/config/api/models/System.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\System;
|
||||
|
||||
/**
|
||||
* System
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'isOk' => function (System $system) {
|
||||
return $system->isOk();
|
||||
},
|
||||
'isInstallable' => function (System $system) {
|
||||
return $system->isInstallable();
|
||||
},
|
||||
'isInstalled' => function (System $system) {
|
||||
return $system->isInstalled();
|
||||
},
|
||||
'isLocal' => function (System $system) {
|
||||
return $system->isLocal();
|
||||
},
|
||||
'multilang' => function () {
|
||||
return $this->kirby()->option('languages', false) !== false;
|
||||
},
|
||||
'languages' => function () {
|
||||
return $this->kirby()->languages();
|
||||
},
|
||||
'license' => function (System $system) {
|
||||
return $system->license();
|
||||
},
|
||||
'requirements' => function (System $system) {
|
||||
return $system->toArray();
|
||||
},
|
||||
'breadcrumbTitle' => function () {
|
||||
return $this->site()->blueprint()->title();
|
||||
},
|
||||
'title' => function () {
|
||||
return $this->site()->title()->value();
|
||||
},
|
||||
'translation' => function () {
|
||||
if ($user = $this->user()) {
|
||||
$translationCode = $user->language();
|
||||
} else {
|
||||
$translationCode = $this->kirby()->option('panel.language', 'en');
|
||||
}
|
||||
|
||||
if ($translation = $this->kirby()->translation($translationCode)) {
|
||||
return $translation;
|
||||
} else {
|
||||
return $this->kirby()->translation('en');
|
||||
}
|
||||
},
|
||||
'kirbytext' => function () {
|
||||
return $this->kirby()->option('panel')['kirbytext'] ?? true;
|
||||
},
|
||||
'user' => function () {
|
||||
return $this->user();
|
||||
},
|
||||
'version' => function () {
|
||||
return $this->kirby()->version();
|
||||
}
|
||||
],
|
||||
'type' => System::class,
|
||||
'views' => [
|
||||
'login' => [
|
||||
'isOk',
|
||||
'isInstalled',
|
||||
'title',
|
||||
'translation'
|
||||
],
|
||||
'troubleshooting' => [
|
||||
'isOk',
|
||||
'isInstallable',
|
||||
'isInstalled',
|
||||
'title',
|
||||
'translation',
|
||||
'requirements'
|
||||
],
|
||||
'panel' => [
|
||||
'breadcrumbTitle',
|
||||
'isOk',
|
||||
'isInstalled',
|
||||
'isLocal',
|
||||
'kirbytext',
|
||||
'languages' => 'compact',
|
||||
'license',
|
||||
'multilang',
|
||||
'requirements',
|
||||
'title',
|
||||
'translation',
|
||||
'user' => 'auth',
|
||||
'version'
|
||||
]
|
||||
],
|
||||
];
|
34
kirby/config/api/models/Translation.php
Executable file
34
kirby/config/api/models/Translation.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Translation;
|
||||
|
||||
/**
|
||||
* Translation
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'author' => function (Translation $translation) {
|
||||
return $translation->author();
|
||||
},
|
||||
'data' => function (Translation $translation) {
|
||||
return $translation->dataWithFallback();
|
||||
},
|
||||
'direction' => function (Translation $translation) {
|
||||
return $translation->direction();
|
||||
},
|
||||
'id' => function (Translation $translation) {
|
||||
return $translation->id();
|
||||
},
|
||||
'name' => function (Translation $translation) {
|
||||
return $translation->name();
|
||||
},
|
||||
],
|
||||
'type' => Translation::class,
|
||||
'views' => [
|
||||
'compact' => [
|
||||
'direction',
|
||||
'id',
|
||||
'name'
|
||||
]
|
||||
]
|
||||
];
|
102
kirby/config/api/models/User.php
Executable file
102
kirby/config/api/models/User.php
Executable file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\Form;
|
||||
use Kirby\Cms\User;
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
return [
|
||||
'default' => function () {
|
||||
return $this->user();
|
||||
},
|
||||
'fields' => [
|
||||
'avatar' => function (User $user) {
|
||||
return $user->avatar() ? $user->avatar()->crop(512) : null;
|
||||
},
|
||||
'blueprint' => function (User $user) {
|
||||
return $user->blueprint();
|
||||
},
|
||||
'content' => function (User $user) {
|
||||
return Form::for($user)->values();
|
||||
},
|
||||
'email' => function (User $user) {
|
||||
return $user->email();
|
||||
},
|
||||
'id' => function (User $user) {
|
||||
return $user->id();
|
||||
},
|
||||
'language' => function (User $user) {
|
||||
return $user->language();
|
||||
},
|
||||
'name' => function (User $user) {
|
||||
return $user->name()->value();
|
||||
},
|
||||
'next' => function (User $user) {
|
||||
return $user->next();
|
||||
},
|
||||
'options' => function (User $user) {
|
||||
return $user->permissions()->toArray();
|
||||
},
|
||||
'permissions' => function (User $user) {
|
||||
return $user->role()->permissions()->toArray();
|
||||
},
|
||||
'prev' => function (User $user) {
|
||||
return $user->prev();
|
||||
},
|
||||
'role' => function (User $user) {
|
||||
return $user->role();
|
||||
},
|
||||
'username' => function (User $user) {
|
||||
return $user->username();
|
||||
}
|
||||
],
|
||||
'type' => User::class,
|
||||
'views' => [
|
||||
'default' => [
|
||||
'avatar',
|
||||
'content',
|
||||
'email',
|
||||
'id',
|
||||
'language',
|
||||
'name',
|
||||
'next' => 'compact',
|
||||
'options',
|
||||
'prev' => 'compact',
|
||||
'role',
|
||||
'username'
|
||||
],
|
||||
'compact' => [
|
||||
'avatar' => 'compact',
|
||||
'id',
|
||||
'email',
|
||||
'language',
|
||||
'name',
|
||||
'role' => 'compact',
|
||||
'username'
|
||||
],
|
||||
'auth' => [
|
||||
'avatar' => 'compact',
|
||||
'permissions',
|
||||
'email',
|
||||
'id',
|
||||
'name',
|
||||
'role',
|
||||
'language'
|
||||
],
|
||||
'panel' => [
|
||||
'avatar' => 'compact',
|
||||
'blueprint',
|
||||
'content',
|
||||
'email',
|
||||
'id',
|
||||
'language',
|
||||
'name',
|
||||
'next' => ['id', 'name'],
|
||||
'options',
|
||||
'prev' => ['id', 'name'],
|
||||
'role',
|
||||
'username',
|
||||
],
|
||||
]
|
||||
];
|
26
kirby/config/api/models/UserBlueprint.php
Executable file
26
kirby/config/api/models/UserBlueprint.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Cms\UserBlueprint;
|
||||
|
||||
/**
|
||||
* UserBlueprint
|
||||
*/
|
||||
return [
|
||||
'fields' => [
|
||||
'name' => function (UserBlueprint $blueprint) {
|
||||
return $blueprint->name();
|
||||
},
|
||||
'options' => function (UserBlueprint $blueprint) {
|
||||
return $blueprint->options();
|
||||
},
|
||||
'tabs' => function (UserBlueprint $blueprint) {
|
||||
return $blueprint->tabs();
|
||||
},
|
||||
'title' => function (UserBlueprint $blueprint) {
|
||||
return $blueprint->title();
|
||||
},
|
||||
],
|
||||
'type' => UserBlueprint::class,
|
||||
'views' => [
|
||||
],
|
||||
];
|
25
kirby/config/api/routes.php
Executable file
25
kirby/config/api/routes.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Api Routes Definitions
|
||||
*/
|
||||
return function ($kirby) {
|
||||
$routes = array_merge(
|
||||
include __DIR__ . '/routes/auth.php',
|
||||
include __DIR__ . '/routes/pages.php',
|
||||
include __DIR__ . '/routes/roles.php',
|
||||
include __DIR__ . '/routes/site.php',
|
||||
include __DIR__ . '/routes/users.php',
|
||||
include __DIR__ . '/routes/files.php',
|
||||
include __DIR__ . '/routes/system.php',
|
||||
include __DIR__ . '/routes/translations.php'
|
||||
);
|
||||
|
||||
// only add the language routes if the
|
||||
// multi language setup is activated
|
||||
if ($kirby->option('languages', false) !== false) {
|
||||
$routes = array_merge($routes, include __DIR__ . '/routes/languages.php');
|
||||
}
|
||||
|
||||
return $routes;
|
||||
};
|
58
kirby/config/api/routes/auth.php
Executable file
58
kirby/config/api/routes/auth.php
Executable file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\NotFoundException;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Exception\PermissionException;
|
||||
|
||||
/**
|
||||
* Authentication
|
||||
*/
|
||||
return [
|
||||
[
|
||||
'pattern' => 'auth',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
if ($user = $this->kirby()->auth()->user()) {
|
||||
return $this->resolve($user)->view('auth');
|
||||
}
|
||||
|
||||
throw new NotFoundException('The user cannot be found');
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'auth/login',
|
||||
'method' => 'POST',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
$auth = $this->kirby()->auth();
|
||||
|
||||
// csrf token check
|
||||
if ($auth->type() === 'session' && $auth->csrf() === false) {
|
||||
throw new InvalidArgumentException('Invalid CSRF token');
|
||||
}
|
||||
|
||||
$email = $this->requestBody('email');
|
||||
$long = $this->requestBody('long');
|
||||
$password = $this->requestBody('password');
|
||||
|
||||
if ($user = $this->kirby()->auth()->login($email, $password, $long)) {
|
||||
return [
|
||||
'code' => 200,
|
||||
'status' => 'ok',
|
||||
'user' => $this->resolve($user)->view('auth')->toArray()
|
||||
];
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('Invalid email or password');
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'auth/logout',
|
||||
'method' => 'POST',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
$this->kirby()->auth()->logout();
|
||||
return true;
|
||||
}
|
||||
],
|
||||
];
|
100
kirby/config/api/routes/files.php
Executable file
100
kirby/config/api/routes/files.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Files Routes
|
||||
*/
|
||||
return [
|
||||
|
||||
[
|
||||
'pattern' => '(:all)/files',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $path) {
|
||||
return $this->parent($path)->files();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files',
|
||||
'method' => 'POST',
|
||||
'action' => function (string $path) {
|
||||
return $this->upload(function ($source, $filename) use ($path) {
|
||||
return $this->parent($path)->createFile([
|
||||
'source' => $source,
|
||||
'template' => $this->requestBody('template'),
|
||||
'filename' => $filename
|
||||
]);
|
||||
});
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/search',
|
||||
'method' => 'POST',
|
||||
'action' => function (string $path) {
|
||||
return $this->parent($path)->files()->query($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/sort',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $path) {
|
||||
return $this->parent($path)->files()->changeSort($this->requestBody('files'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $path, string $filename) {
|
||||
return $this->file($path, $filename);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $path, string $filename) {
|
||||
return $this->file($path, $filename)->update($this->requestBody(), $this->language(), true);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)',
|
||||
'method' => 'POST',
|
||||
'action' => function (string $path, string $filename) {
|
||||
return $this->upload(function ($source) use ($path, $filename) {
|
||||
return $this->file($path, $filename)->replace($source);
|
||||
});
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)',
|
||||
'method' => 'DELETE',
|
||||
'action' => function (string $path, string $filename) {
|
||||
return $this->file($path, $filename)->delete();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)/name',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $path, string $filename) {
|
||||
return $this->file($path, $filename)->changeName($this->requestBody('name'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)/sections/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $path, string $filename, string $sectionName) {
|
||||
if ($section = $this->file($path, $filename)->blueprint()->section($sectionName)) {
|
||||
return $section->toResponse();
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => '(:all)/files/(:any)/fields/(:any)/(:all?)',
|
||||
'method' => 'ALL',
|
||||
'action' => function (string $parent, string $filename, string $fieldName, string $path = null) {
|
||||
if ($file = $this->file($parent, $filename)) {
|
||||
return $this->fieldApi($file, $fieldName, $path);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
];
|
46
kirby/config/api/routes/languages.php
Executable file
46
kirby/config/api/routes/languages.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Roles Routes
|
||||
*/
|
||||
return [
|
||||
[
|
||||
'pattern' => 'languages',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
return $this->kirby()->languages();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'languages',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->kirby()->languages()->create($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'languages/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $code) {
|
||||
return $this->kirby()->languages()->find($code);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'languages/(:any)',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $code) {
|
||||
if ($language = $this->kirby()->languages()->find($code)) {
|
||||
return $language->update($this->requestBody());
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'languages/(:any)',
|
||||
'method' => 'DELETE',
|
||||
'action' => function (string $code) {
|
||||
if ($language = $this->kirby()->languages()->find($code)) {
|
||||
return $language->delete();
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
105
kirby/config/api/routes/pages.php
Executable file
105
kirby/config/api/routes/pages.php
Executable file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Page Routes
|
||||
*/
|
||||
return [
|
||||
|
||||
[
|
||||
'pattern' => 'pages/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->update($this->requestBody(), $this->language(), true);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)',
|
||||
'method' => 'DELETE',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->delete($this->requestBody('force', false));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/children',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->children();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/children',
|
||||
'method' => 'POST',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->createChild($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/children/blueprints',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->blueprints($this->requestQuery('section'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/children/search',
|
||||
'method' => 'POST',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->children()->query($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/slug',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->changeSlug($this->requestBody('slug'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/status',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->changeStatus($this->requestBody('status'), $this->requestBody('position'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/template',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->changeTemplate($this->requestBody('template'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/title',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->page($id)->changeTitle($this->requestBody('title'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/sections/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id, string $sectionName) {
|
||||
if ($section = $this->page($id)->blueprint()->section($sectionName)) {
|
||||
return $section->toResponse();
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'pages/(:any)/fields/(:any)/(:all?)',
|
||||
'method' => 'ALL',
|
||||
'action' => function (string $id, string $fieldName, string $path = null) {
|
||||
if ($page = $this->page($id)) {
|
||||
return $this->fieldApi($page, $fieldName, $path);
|
||||
}
|
||||
}
|
||||
],
|
||||
];
|
21
kirby/config/api/routes/roles.php
Executable file
21
kirby/config/api/routes/roles.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Roles Routes
|
||||
*/
|
||||
return [
|
||||
[
|
||||
'pattern' => 'roles',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
return $this->kirby()->roles();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'roles/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $name) {
|
||||
return $this->kirby()->roles()->find($name);
|
||||
}
|
||||
]
|
||||
];
|
95
kirby/config/api/routes/site.php
Executable file
95
kirby/config/api/routes/site.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Site Routes
|
||||
*/
|
||||
return [
|
||||
|
||||
[
|
||||
'pattern' => 'site',
|
||||
'action' => function () {
|
||||
return $this->site();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site',
|
||||
'method' => 'PATCH',
|
||||
'action' => function () {
|
||||
return $this->site()->update($this->requestBody(), $this->language(), true);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/children',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
return $this->site()->children();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/children',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->site()->createChild($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/children/blueprints',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
return $this->site()->blueprints($this->requestQuery('section'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/children/search',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->site()->children()->query($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/find',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->site()->find(false, ...$this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/title',
|
||||
'method' => 'PATCH',
|
||||
'action' => function () {
|
||||
return $this->site()->changeTitle($this->requestBody('title'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/search',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
return $this->site()
|
||||
->index(true)
|
||||
->filterBy('isReadable', true)
|
||||
->search($this->requestQuery('q'), [
|
||||
'score' => [
|
||||
'id' => 64,
|
||||
'title' => 64,
|
||||
]
|
||||
]);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/sections/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $sectionName) {
|
||||
if ($section = $this->site()->blueprint()->section($sectionName)) {
|
||||
return $section->toResponse();
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'site/fields/(:any)/(:all?)',
|
||||
'method' => 'ALL',
|
||||
'action' => function (string $fieldName, string $path = null) {
|
||||
return $this->fieldApi($this->site(), $fieldName, $path);
|
||||
}
|
||||
]
|
||||
|
||||
];
|
72
kirby/config/api/routes/system.php
Executable file
72
kirby/config/api/routes/system.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System Routes
|
||||
*/
|
||||
return [
|
||||
|
||||
[
|
||||
'pattern' => 'system',
|
||||
'method' => 'GET',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
$system = $this->kirby()->system();
|
||||
|
||||
if ($this->kirby()->user()) {
|
||||
return $system;
|
||||
} else {
|
||||
if ($system->isOk() === true) {
|
||||
$info = $this->resolve($system)->view('login')->toArray();
|
||||
} else {
|
||||
$info = $this->resolve($system)->view('troubleshooting')->toArray();
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'data' => $info,
|
||||
'type' => 'model'
|
||||
];
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'system/register',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->kirby()->system()->register($this->requestBody('license'), $this->requestBody('email'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'system/install',
|
||||
'method' => 'POST',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
$system = $this->kirby()->system();
|
||||
$auth = $this->kirby()->auth();
|
||||
|
||||
// csrf token check
|
||||
if ($auth->type() === 'session' && $auth->csrf() === false) {
|
||||
throw new InvalidArgumentException('Invalid CSRF token');
|
||||
}
|
||||
|
||||
if ($system->isOk() === false) {
|
||||
throw new Exception('The server is not setup correctly');
|
||||
}
|
||||
|
||||
if ($system->isInstalled() === true) {
|
||||
throw new Exception('The panel is already installed');
|
||||
}
|
||||
|
||||
// create the first user
|
||||
$user = $this->users()->create($this->requestBody());
|
||||
$token = $user->login($this->requestBody('password'));
|
||||
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'token' => $token,
|
||||
'user' => $this->resolve($user)->view('auth')->toArray()
|
||||
];
|
||||
}
|
||||
]
|
||||
|
||||
];
|
24
kirby/config/api/routes/translations.php
Executable file
24
kirby/config/api/routes/translations.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Translations Routes
|
||||
*/
|
||||
return [
|
||||
[
|
||||
'pattern' => 'translations',
|
||||
'method' => 'GET',
|
||||
'auth' => false,
|
||||
'action' => function () {
|
||||
return $this->kirby()->translations();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'translations/(:any)',
|
||||
'method' => 'GET',
|
||||
'auth' => false,
|
||||
'action' => function (string $code) {
|
||||
return $this->kirby()->translations()->find($code);
|
||||
}
|
||||
]
|
||||
|
||||
];
|
137
kirby/config/api/routes/users.php
Executable file
137
kirby/config/api/routes/users.php
Executable file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
use Kirby\Toolkit\F;
|
||||
|
||||
/**
|
||||
* User Routes
|
||||
*/
|
||||
return [
|
||||
|
||||
[
|
||||
'pattern' => 'users',
|
||||
'method' => 'GET',
|
||||
'action' => function () {
|
||||
return $this->users();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->users()->create($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/search',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
return $this->users()->query($this->requestBody());
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->update($this->requestBody(), $this->language(), true);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)',
|
||||
'method' => 'DELETE',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->delete();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/avatar',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->avatar();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/avatar',
|
||||
'method' => 'POST',
|
||||
'action' => function (string $id) {
|
||||
if ($avatar = $this->user($id)->avatar()) {
|
||||
$avatar->delete();
|
||||
}
|
||||
|
||||
return $this->upload(function ($source, $filename) use ($id) {
|
||||
return $this->user($id)->createFile([
|
||||
'filename' => 'profile.' . F::extension($filename),
|
||||
'template' => 'avatar',
|
||||
'source' => $source
|
||||
]);
|
||||
}, $single = true);
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/avatar',
|
||||
'method' => 'DELETE',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->avatar()->delete();
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/email',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->changeEmail($this->requestBody('email'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/language',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->changeLanguage($this->requestBody('language'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/name',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->changeName($this->requestBody('name'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/password',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->changePassword($this->requestBody('password'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/role',
|
||||
'method' => 'PATCH',
|
||||
'action' => function (string $id) {
|
||||
return $this->user($id)->changeRole($this->requestBody('role'));
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/sections/(:any)',
|
||||
'method' => 'GET',
|
||||
'action' => function (string $id, string $sectionName) {
|
||||
if ($section = $this->user($id)->blueprint()->section($sectionName)) {
|
||||
return $section->toResponse();
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'pattern' => 'users/(:any)/fields/(:any)/(:all?)',
|
||||
'method' => 'ALL',
|
||||
'action' => function (string $id, string $fieldName, string $path = null) {
|
||||
if ($user = $this->user($id)) {
|
||||
return $this->fieldApi($user, $fieldName, $path);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
];
|
Reference in New Issue
Block a user