1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-24 13:52:56 +02:00

feat(admin-plugin): update Admin plugin #212 #186

Move from JSON to YAML
This commit is contained in:
Awilum
2019-08-21 13:31:06 +03:00
parent 43d2efb93d
commit 8a50d92ef3
4 changed files with 12 additions and 12 deletions

View File

@@ -62,9 +62,9 @@ class PluginsController extends Controller
$data = $request->getParsedBody();
// Update settings
$plugin_settings = JsonParser::decode(Filesystem::read(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml'));
$plugin_settings = Parser::decode(Filesystem::read(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml'), 'yaml');
Arr::set($plugin_settings, 'enabled', ($data['plugin-status'] === 'true'));
Filesystem::write(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml', JsonParser::encode($plugin_settings));
Filesystem::write(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml', Parser::encode($plugin_settings, 'yaml'));
// Clear doctrine cache
$this->cache->clear('doctrine');

View File

@@ -141,7 +141,7 @@ class SettingsController extends Controller
Arr::set($data, 'entries.media.upload_images_width', (int) $data['entries']['media']['upload_images_width']);
Arr::set($data, 'entries.media.upload_images_height', (int) $data['entries']['media']['upload_images_height']);
if (Filesystem::write(PATH['config']['site'] . '/settings.yaml', JsonParser::encode(array_merge($this->registry->get('settings'), $data)))) {
if (Filesystem::write(PATH['config']['site'] . '/settings.yaml', Parser::encode(array_merge($this->registry->get('settings'), $data)), 'yaml')) {
$this->flash->addMessage('success', __('admin_message_settings_saved'));
} else {
$this->flash->addMessage('error', __('admin_message_settings_was_not_saved'));

View File

@@ -64,9 +64,9 @@ class ThemesController extends Controller
$data = $request->getParsedBody();
// Update current theme settings
$theme_settings = JsonParser::decode(Filesystem::read(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml'));
$theme_settings = Parser::decode(Filesystem::read(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml'), 'yaml');
Arr::set($theme_settings, 'enabled', ($data['theme-status'] === 'true'));
Filesystem::write(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml', JsonParser::encode($theme_settings));
Filesystem::write(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml', Parser::encode($theme_settings, 'yaml'));
// Get themes list
$themes_list = $this->themes->getThemes();
@@ -82,16 +82,16 @@ class ThemesController extends Controller
continue;
}
$theme_settings = JsonParser::decode(Filesystem::read($theme_settings_file));
$theme_settings = Parser::decode(Filesystem::read($theme_settings_file), 'yaml');
Arr::set($theme_settings, 'enabled', false);
Filesystem::write($theme_settings_file, JsonParser::encode($theme_settings));
Filesystem::write($theme_settings_file, Parser::encode($theme_settings, 'yaml'));
}
}
// Update theme in the site settings
$settings = JsonParser::decode(Filesystem::read(PATH['config']['site'] . '/settings.yaml'));
$settings = Parser::decode(Filesystem::read(PATH['config']['site'] . '/settings.yaml'), 'yaml');
Arr::set($settings, 'theme', $data['theme-id']);
Filesystem::write(PATH['config']['site'] . '/settings.yaml', JsonParser::encode($settings));
Filesystem::write(PATH['config']['site'] . '/settings.yaml', Parser::encode($settings, 'yaml'));
// clear cache
$this->cache->clear('doctrine');

View File

@@ -67,7 +67,7 @@ class UsersController extends Controller
$data = $request->getParsedBody();
if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $data['username'] . '.yaml')) {
$user_file = JsonParser::decode(Filesystem::read($_user_file));
$user_file = Parser::decode(Filesystem::read($_user_file), 'yaml');
if (password_verify(trim($data['password']), $user_file['hashed_password'])) {
Session::set('username', $user_file['username']);
Session::set('role', $user_file['role']);
@@ -125,14 +125,14 @@ class UsersController extends Controller
Filesystem::createDir(PATH['site'] . '/accounts/');
if (Filesystem::write(
PATH['site'] . '/accounts/' . $data['username'] . '.yaml',
JsonParser::encode([
Parser::encode([
'username' => $this->slugify->slugify($data['username']),
'hashed_password' => password_hash($data['password'], PASSWORD_BCRYPT),
'email' => $data['email'],
'role' => 'admin',
'state' => 'enabled',
'uuid' => Uuid::uuid4()->toString(),
])
], 'yaml')
)) {
return $response->withRedirect($this->router->pathFor('admin.users.login'));
}