mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 09:42:43 +01:00
Merge branch 'master' into feature/user-permissions
This commit is contained in:
commit
a8068d3bd0
@ -209,8 +209,7 @@ class Options extends AbstractController
|
|||||||
|
|
||||||
// Update config file if options differ
|
// Update config file if options differ
|
||||||
if ($options !== $old) {
|
if ($options !== $old) {
|
||||||
$fileContent = YAML::encode($options);
|
FileSystem::write(CONFIG_PATH . $type . '.yml', YAML::encode($options));
|
||||||
FileSystem::write(CONFIG_PATH . $type . '.yml', $fileContent);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,36 +63,36 @@ class Pages extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->ensurePermission('pages.create');
|
$this->ensurePermission('pages.create');
|
||||||
|
|
||||||
$this->data = new DataGetter(HTTPRequest::postData());
|
$data = new DataGetter(HTTPRequest::postData());
|
||||||
|
|
||||||
// Ensure no required data is missing
|
// Ensure no required data is missing
|
||||||
foreach (array('title', 'slug', 'template', 'parent') as $var) {
|
foreach (array('title', 'slug', 'template', 'parent') as $var) {
|
||||||
if (!$this->data->has($var)) {
|
if (!$data->has($var)) {
|
||||||
$this->notify($this->label('pages.page.cannot-create.var-missing', $var), 'error');
|
$this->notify($this->label('pages.page.cannot-create.var-missing', $var), 'error');
|
||||||
$this->redirect('/pages/', 302, true);
|
$this->redirect('/pages/', 302, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure there isn't a page with the same uri
|
// Ensure there isn't a page with the same uri
|
||||||
if ($this->site->findPage($this->data->get('slug'))) {
|
if ($this->site->findPage($data->get('slug'))) {
|
||||||
$this->notify($this->label('pages.page.cannot-create.already-exists'), 'error');
|
$this->notify($this->label('pages.page.cannot-create.already-exists'), 'error');
|
||||||
$this->redirect('/pages/', 302, true);
|
$this->redirect('/pages/', 302, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $this->resolveParent($this->data->get('parent'));
|
$parent = $this->resolveParent($data->get('parent'));
|
||||||
|
|
||||||
if (is_null($parent)) {
|
if (is_null($parent)) {
|
||||||
$this->notify($this->label('pages.page.cannot-create.invalid-parent'), 'error');
|
$this->notify($this->label('pages.page.cannot-create.invalid-parent'), 'error');
|
||||||
$this->redirect('/pages/', 302, true);
|
$this->redirect('/pages/', 302, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$scheme = $this->scheme($this->data->get('template'));
|
$scheme = $this->scheme($data->get('template'));
|
||||||
|
|
||||||
$path = $parent->path() . $this->makePageNum($parent, $scheme->get('num')) . '-' . $this->data->get('slug') . DS;
|
$path = $parent->path() . $this->makePageNum($parent, $scheme->get('num')) . '-' . $data->get('slug') . DS;
|
||||||
|
|
||||||
// Let's create the page
|
// Let's create the page
|
||||||
try {
|
try {
|
||||||
$newPage = $this->createPage($path, $this->data->get('template'), $this->data->get('title'));
|
$newPage = $this->createPage($path, $data->get('template'), $data->get('title'));
|
||||||
$this->notify($this->label('pages.page.created'), 'success');
|
$this->notify($this->label('pages.page.created'), 'success');
|
||||||
$this->redirect('/pages/' . trim($newPage->slug(), '/') . '/edit/', 302, true);
|
$this->redirect('/pages/' . trim($newPage->slug(), '/') . '/edit/', 302, true);
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
@ -119,30 +119,30 @@ class Pages extends AbstractController
|
|||||||
switch (HTTPRequest::method()) {
|
switch (HTTPRequest::method()) {
|
||||||
case 'GET':
|
case 'GET':
|
||||||
// Load data from the page itself
|
// Load data from the page itself
|
||||||
$this->data = new DataGetter($this->page->data());
|
$data = new DataGetter($this->page->data());
|
||||||
|
|
||||||
// Validate fields against data
|
// Validate fields against data
|
||||||
$this->fields->validate($this->data);
|
$this->fields->validate($data);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'POST':
|
case 'POST':
|
||||||
// Load data from POST variables
|
// Load data from POST variables
|
||||||
$this->data = new DataGetter(HTTPRequest::postData());
|
$data = new DataGetter(HTTPRequest::postData());
|
||||||
|
|
||||||
// Validate fields against data
|
// Validate fields against data
|
||||||
$this->fields->validate($this->data);
|
$this->fields->validate($data);
|
||||||
|
|
||||||
// Ensure no required data is missing
|
// Ensure no required data is missing
|
||||||
foreach (array('title', 'content') as $var) {
|
foreach (array('title', 'content') as $var) {
|
||||||
if (!$this->data->has($var)) {
|
if (!$data->has($var)) {
|
||||||
$this->notify($this->label('pages.page.cannot-edit.var-missing', $var), 'error');
|
$this->notify($this->label('pages.page.cannot-edit.var-missing', $var), 'error');
|
||||||
$this->redirect('/pages/' . $params->get('page') . '/edit/', 302, true);
|
$this->redirect('/pages/' . $params->get('page') . '/edit/', 302, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the page
|
// Update the page
|
||||||
$this->page = $this->updatePage($this->page, $this->data);
|
$this->page = $this->updatePage($this->page, $data);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -171,27 +171,27 @@ class Pages extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->ensurePermission('pages.reorder');
|
$this->ensurePermission('pages.reorder');
|
||||||
|
|
||||||
$this->data = new DataGetter(HTTPRequest::postData());
|
$data = new DataGetter(HTTPRequest::postData());
|
||||||
|
|
||||||
foreach (array('parent', 'from', 'to') as $var) {
|
foreach (array('parent', 'from', 'to') as $var) {
|
||||||
if (!$this->data->has($var)) {
|
if (!$data->has($var)) {
|
||||||
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($this->data->get('from')) || !is_numeric($this->data->get('to'))) {
|
if (!is_numeric($data->get('from')) || !is_numeric($data->get('to'))) {
|
||||||
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $this->resolveParent($this->data->get('parent'));
|
$parent = $this->resolveParent($data->get('parent'));
|
||||||
if (is_null($parent) || !$parent->hasChildren()) {
|
if (is_null($parent) || !$parent->hasChildren()) {
|
||||||
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
$pages = $parent->children()->toArray();
|
$pages = $parent->children()->toArray();
|
||||||
|
|
||||||
$from = max(0, $this->data->get('from'));
|
$from = max(0, $data->get('from'));
|
||||||
$to = max(0, $this->data->get('to'));
|
$to = max(0, $data->get('to'));
|
||||||
if ($to === $from) {
|
if ($to === $from) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -24,32 +24,30 @@ class Register extends AbstractController
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'POST':
|
case 'POST':
|
||||||
$this->data = new DataGetter(HTTPRequest::postData());
|
$data = new DataGetter(HTTPRequest::postData());
|
||||||
|
|
||||||
foreach (array('username', 'fullname', 'password', 'email') as $var) {
|
foreach (array('username', 'fullname', 'password', 'email') as $var) {
|
||||||
if (!$this->data->has($var)) {
|
if (!$data->has($var)) {
|
||||||
$this->notify($this->label('users.user.cannot-create.var-missing', $var), 'error');
|
$this->notify($this->label('users.user.cannot-create.var-missing', $var), 'error');
|
||||||
$this->redirectToPanel(302, true);
|
$this->redirectToPanel(302, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$userdata = array(
|
$userData = array(
|
||||||
'username' => $this->data->get('username'),
|
'username' => $data->get('username'),
|
||||||
'fullname' => $this->data->get('fullname'),
|
'fullname' => $data->get('fullname'),
|
||||||
'hash' => Password::hash($this->data->get('password')),
|
'hash' => Password::hash($data->get('password')),
|
||||||
'email' => $this->data->get('email'),
|
'email' => $data->get('email'),
|
||||||
'language' => $this->data->get('language'),
|
'language' => $data->get('language'),
|
||||||
'avatar' => null,
|
'avatar' => null,
|
||||||
'role' => 'admin'
|
'role' => 'admin'
|
||||||
);
|
);
|
||||||
|
|
||||||
$fileContent = YAML::encode($userdata);
|
FileSystem::write(ACCOUNTS_PATH . $data->get('username') . '.yml', YAML::encode($userData));
|
||||||
|
|
||||||
FileSystem::write(ACCOUNTS_PATH . $this->data->get('username') . '.yml', $fileContent);
|
Session::set('FORMWORK_USERNAME', $data->get('username'));
|
||||||
|
$time = $this->log('access')->log($data->get('username'));
|
||||||
Session::set('FORMWORK_USERNAME', $this->data->get('username'));
|
$this->registry('lastAccess')->set($data->get('username'), $time);
|
||||||
$time = $this->log('access')->log($this->data->get('username'));
|
|
||||||
$this->registry('lastAccess')->set($this->data->get('username'), $time);
|
|
||||||
|
|
||||||
$this->redirectToPanel(302, true);
|
$this->redirectToPanel(302, true);
|
||||||
break;
|
break;
|
||||||
|
@ -38,35 +38,33 @@ class Users extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->ensurePermission('users.create');
|
$this->ensurePermission('users.create');
|
||||||
|
|
||||||
$this->data = new DataGetter(HTTPRequest::postData());
|
$data = new DataGetter(HTTPRequest::postData());
|
||||||
|
|
||||||
// Ensure no required data is missing
|
// Ensure no required data is missing
|
||||||
foreach (array('username', 'fullname', 'password', 'email', 'language') as $var) {
|
foreach (array('username', 'fullname', 'password', 'email', 'language') as $var) {
|
||||||
if (!$this->data->has($var)) {
|
if (!$data->has($var)) {
|
||||||
$this->notify($this->label('users.user.cannot-create.var-missing', $var), 'error');
|
$this->notify($this->label('users.user.cannot-create.var-missing', $var), 'error');
|
||||||
$this->redirect('/users/', 302, true);
|
$this->redirect('/users/', 302, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure there isn't a user with the same username
|
// Ensure there isn't a user with the same username
|
||||||
if (Admin::instance()->users()->has($this->data->get('username'))) {
|
if (Admin::instance()->users()->has($data->get('username'))) {
|
||||||
$this->notify($this->label('users.user.cannot-create.already-exists'), 'error');
|
$this->notify($this->label('users.user.cannot-create.already-exists'), 'error');
|
||||||
$this->redirect('/users/', 302, true);
|
$this->redirect('/users/', 302, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$userdata = array(
|
$userData = array(
|
||||||
'username' => $this->data->get('username'),
|
'username' => $data->get('username'),
|
||||||
'fullname' => $this->data->get('fullname'),
|
'fullname' => $data->get('fullname'),
|
||||||
'hash' => Password::hash($this->data->get('password')),
|
'hash' => Password::hash($data->get('password')),
|
||||||
'email' => $this->data->get('email'),
|
'email' => $data->get('email'),
|
||||||
'language' => $this->data->get('language'),
|
'language' => $data->get('language'),
|
||||||
'avatar' => null,
|
'avatar' => null,
|
||||||
'role' => 'user'
|
'role' => 'user'
|
||||||
);
|
);
|
||||||
|
|
||||||
$fileContent = YAML::encode($userdata);
|
FileSystem::write(ACCOUNTS_PATH . $data->get('username') . '.yml', YAML::encode($userData));
|
||||||
|
|
||||||
FileSystem::write(ACCOUNTS_PATH . $this->data->get('username') . '.yml', $fileContent);
|
|
||||||
|
|
||||||
$this->notify($this->label('users.user.created'), 'success');
|
$this->notify($this->label('users.user.created'), 'success');
|
||||||
$this->redirect('/users/', 302, true);
|
$this->redirect('/users/', 302, true);
|
||||||
@ -168,9 +166,7 @@ class Users extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileContent = YAML::encode($data);
|
FileSystem::write(ACCOUNTS_PATH . $data['username'] . '.yml', YAML::encode($data));
|
||||||
|
|
||||||
FileSystem::write(ACCOUNTS_PATH . $data['username'] . '.yml', $fileContent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function uploadAvatar(User $user)
|
protected function uploadAvatar(User $user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user