mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 01:32:25 +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
|
||||
if ($options !== $old) {
|
||||
$fileContent = YAML::encode($options);
|
||||
FileSystem::write(CONFIG_PATH . $type . '.yml', $fileContent);
|
||||
FileSystem::write(CONFIG_PATH . $type . '.yml', YAML::encode($options));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -63,36 +63,36 @@ class Pages extends AbstractController
|
||||
{
|
||||
$this->ensurePermission('pages.create');
|
||||
|
||||
$this->data = new DataGetter(HTTPRequest::postData());
|
||||
$data = new DataGetter(HTTPRequest::postData());
|
||||
|
||||
// Ensure no required data is missing
|
||||
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->redirect('/pages/', 302, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 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->redirect('/pages/', 302, true);
|
||||
}
|
||||
|
||||
$parent = $this->resolveParent($this->data->get('parent'));
|
||||
$parent = $this->resolveParent($data->get('parent'));
|
||||
|
||||
if (is_null($parent)) {
|
||||
$this->notify($this->label('pages.page.cannot-create.invalid-parent'), 'error');
|
||||
$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
|
||||
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->redirect('/pages/' . trim($newPage->slug(), '/') . '/edit/', 302, true);
|
||||
} catch (RuntimeException $e) {
|
||||
@ -119,30 +119,30 @@ class Pages extends AbstractController
|
||||
switch (HTTPRequest::method()) {
|
||||
case 'GET':
|
||||
// Load data from the page itself
|
||||
$this->data = new DataGetter($this->page->data());
|
||||
$data = new DataGetter($this->page->data());
|
||||
|
||||
// Validate fields against data
|
||||
$this->fields->validate($this->data);
|
||||
$this->fields->validate($data);
|
||||
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
// Load data from POST variables
|
||||
$this->data = new DataGetter(HTTPRequest::postData());
|
||||
$data = new DataGetter(HTTPRequest::postData());
|
||||
|
||||
// Validate fields against data
|
||||
$this->fields->validate($this->data);
|
||||
$this->fields->validate($data);
|
||||
|
||||
// Ensure no required data is missing
|
||||
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->redirect('/pages/' . $params->get('page') . '/edit/', 302, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the page
|
||||
$this->page = $this->updatePage($this->page, $this->data);
|
||||
$this->page = $this->updatePage($this->page, $data);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -171,27 +171,27 @@ class Pages extends AbstractController
|
||||
{
|
||||
$this->ensurePermission('pages.reorder');
|
||||
|
||||
$this->data = new DataGetter(HTTPRequest::postData());
|
||||
$data = new DataGetter(HTTPRequest::postData());
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
$parent = $this->resolveParent($this->data->get('parent'));
|
||||
$parent = $this->resolveParent($data->get('parent'));
|
||||
if (is_null($parent) || !$parent->hasChildren()) {
|
||||
JSONResponse::error($this->label('pages.page.cannot-move'))->send();
|
||||
}
|
||||
|
||||
$pages = $parent->children()->toArray();
|
||||
|
||||
$from = max(0, $this->data->get('from'));
|
||||
$to = max(0, $this->data->get('to'));
|
||||
$from = max(0, $data->get('from'));
|
||||
$to = max(0, $data->get('to'));
|
||||
if ($to === $from) {
|
||||
return;
|
||||
}
|
||||
|
@ -24,32 +24,30 @@ class Register extends AbstractController
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$this->data = new DataGetter(HTTPRequest::postData());
|
||||
$data = new DataGetter(HTTPRequest::postData());
|
||||
|
||||
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->redirectToPanel(302, true);
|
||||
}
|
||||
}
|
||||
|
||||
$userdata = array(
|
||||
'username' => $this->data->get('username'),
|
||||
'fullname' => $this->data->get('fullname'),
|
||||
'hash' => Password::hash($this->data->get('password')),
|
||||
'email' => $this->data->get('email'),
|
||||
'language' => $this->data->get('language'),
|
||||
$userData = array(
|
||||
'username' => $data->get('username'),
|
||||
'fullname' => $data->get('fullname'),
|
||||
'hash' => Password::hash($data->get('password')),
|
||||
'email' => $data->get('email'),
|
||||
'language' => $data->get('language'),
|
||||
'avatar' => null,
|
||||
'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', $this->data->get('username'));
|
||||
$time = $this->log('access')->log($this->data->get('username'));
|
||||
$this->registry('lastAccess')->set($this->data->get('username'), $time);
|
||||
Session::set('FORMWORK_USERNAME', $data->get('username'));
|
||||
$time = $this->log('access')->log($data->get('username'));
|
||||
$this->registry('lastAccess')->set($data->get('username'), $time);
|
||||
|
||||
$this->redirectToPanel(302, true);
|
||||
break;
|
||||
|
@ -38,35 +38,33 @@ class Users extends AbstractController
|
||||
{
|
||||
$this->ensurePermission('users.create');
|
||||
|
||||
$this->data = new DataGetter(HTTPRequest::postData());
|
||||
$data = new DataGetter(HTTPRequest::postData());
|
||||
|
||||
// Ensure no required data is missing
|
||||
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->redirect('/users/', 302, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 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->redirect('/users/', 302, true);
|
||||
}
|
||||
|
||||
$userdata = array(
|
||||
'username' => $this->data->get('username'),
|
||||
'fullname' => $this->data->get('fullname'),
|
||||
'hash' => Password::hash($this->data->get('password')),
|
||||
'email' => $this->data->get('email'),
|
||||
'language' => $this->data->get('language'),
|
||||
$userData = array(
|
||||
'username' => $data->get('username'),
|
||||
'fullname' => $data->get('fullname'),
|
||||
'hash' => Password::hash($data->get('password')),
|
||||
'email' => $data->get('email'),
|
||||
'language' => $data->get('language'),
|
||||
'avatar' => null,
|
||||
'role' => 'user'
|
||||
);
|
||||
|
||||
$fileContent = YAML::encode($userdata);
|
||||
|
||||
FileSystem::write(ACCOUNTS_PATH . $this->data->get('username') . '.yml', $fileContent);
|
||||
FileSystem::write(ACCOUNTS_PATH . $data->get('username') . '.yml', YAML::encode($userData));
|
||||
|
||||
$this->notify($this->label('users.user.created'), 'success');
|
||||
$this->redirect('/users/', 302, true);
|
||||
@ -168,9 +166,7 @@ class Users extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
$fileContent = YAML::encode($data);
|
||||
|
||||
FileSystem::write(ACCOUNTS_PATH . $data['username'] . '.yml', $fileContent);
|
||||
FileSystem::write(ACCOUNTS_PATH . $data['username'] . '.yml', YAML::encode($data));
|
||||
}
|
||||
|
||||
protected function uploadAvatar(User $user)
|
||||
|
Loading…
x
Reference in New Issue
Block a user