mirror of
https://github.com/flextype/flextype.git
synced 2025-08-13 16:44:36 +02:00
Flextype Slim Integration - next round of integration
This commit is contained in:
@@ -7,9 +7,76 @@ use Flextype\Component\Http\Http;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Flextype\Component\Registry\Registry;
|
||||
use Flextype\Component\Token\Token;
|
||||
use Flextype\Component\Date\Date;
|
||||
use Flextype\Component\Notification\Notification;
|
||||
use function Flextype\Component\I18n\__;
|
||||
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
$app->get('/admin/settings', function (Request $request, Response $response, array $args) {
|
||||
|
||||
$entries = [];
|
||||
foreach ($this->entries->fetchAll('', 'date', 'DESC') as $entry) {
|
||||
$entries[$entry['slug']] = $entry['title'];
|
||||
}
|
||||
|
||||
$themes = [];
|
||||
foreach (Filesystem::listContents(PATH['themes']) as $theme) {
|
||||
if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . $theme['dirname'] . '.yaml')) {
|
||||
$themes[$theme['dirname']] = $theme['dirname'];
|
||||
}
|
||||
}
|
||||
|
||||
$available_locales = Filesystem::listContents(PATH['plugins'] . '/admin/languages/');
|
||||
$system_locales = $this->plugins->getLocales();
|
||||
$locales = [];
|
||||
foreach ($available_locales as $locale) {
|
||||
if ($locale['type'] == 'file' && $locale['extension'] == 'yaml') {
|
||||
$locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName'];
|
||||
}
|
||||
}
|
||||
|
||||
$cache_driver = ['auto' => 'Auto Detect',
|
||||
'file' => 'File',
|
||||
'apcu' => 'APCu',
|
||||
'wincache' => 'WinCache',
|
||||
'memcached' => 'Memcached',
|
||||
'redis' => 'Redis',
|
||||
'sqlite3' => 'SQLite3',
|
||||
'zend' => 'Zend',
|
||||
'array' => 'Array'];
|
||||
|
||||
return $this->view->render($response,
|
||||
'plugins/admin/views/templates/system/settings/index.html', [
|
||||
'timezones' => Date::timezones(),
|
||||
'settings' => $this->registry->get('settings'),
|
||||
'cache_driver' => $cache_driver,
|
||||
'locales' => $locales,
|
||||
'entries' => $entries,
|
||||
'themes' => $themes,
|
||||
'links' => [
|
||||
'settings' => [
|
||||
'link' => '/admin/settings',
|
||||
'title' => __('admin_settings'),
|
||||
'attributes' => ['class' => 'navbar-item active']
|
||||
]
|
||||
],
|
||||
'buttons' => [
|
||||
'save' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn']
|
||||
],
|
||||
'settings_clear_cache' => [
|
||||
'link' => '/admin/settings?clear_cache=1&token=' . Token::generate(),
|
||||
'title' => __('admin_clear_cache'),
|
||||
'attributes' => ['class' => 'float-right btn']
|
||||
]
|
||||
]
|
||||
]);
|
||||
})->setName('information');
|
||||
|
||||
class SettingsManager
|
||||
{
|
||||
public static function getSettingsManager()
|
||||
@@ -71,56 +138,4 @@ class SettingsManager
|
||||
}
|
||||
}
|
||||
|
||||
private static function localesList()
|
||||
{
|
||||
$available_locales = Filesystem::listContents(PATH['plugins'] . '/admin/languages/');
|
||||
$system_locales = Plugins::getLocales();
|
||||
|
||||
$locales = [];
|
||||
|
||||
foreach ($available_locales as $locale) {
|
||||
if ($locale['type'] == 'file' && $locale['extension'] == 'yaml') {
|
||||
$locales[$locale['basename']] = $system_locales[$locale['basename']]['nativeName'];
|
||||
}
|
||||
}
|
||||
|
||||
return $locales;
|
||||
}
|
||||
|
||||
private static function entriesList()
|
||||
{
|
||||
$entries = [];
|
||||
|
||||
foreach (Entries::fetchAll('', 'date', 'DESC') as $entry) {
|
||||
$entries[$entry['slug']] = $entry['title'];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
private static function themesList()
|
||||
{
|
||||
$themes = [];
|
||||
|
||||
foreach (Filesystem::listContents(PATH['themes']) as $theme) {
|
||||
if ($theme['type'] == 'dir' && Filesystem::has($theme['path'] . '/' . $theme['dirname'] . '.yaml')) {
|
||||
$themes[$theme['dirname']] = $theme['dirname'];
|
||||
}
|
||||
}
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
private static function cacheDriverList()
|
||||
{
|
||||
return ['auto' => 'Auto Detect',
|
||||
'file' => 'File',
|
||||
'apcu' => 'APCu',
|
||||
'wincache' => 'WinCache',
|
||||
'memcached' => 'Memcached',
|
||||
'redis' => 'Redis',
|
||||
'sqlite3' => 'SQLite3',
|
||||
'zend' => 'Zend',
|
||||
'array' => 'Array'];
|
||||
}
|
||||
}
|
||||
|
@@ -13,10 +13,10 @@ use Psr\Container\ContainerInterface;
|
||||
|
||||
$app->get('/admin/login', UsersController::class . ':login')->setName('admin.login');
|
||||
$app->get('/admin/profile', UsersController::class . ':profile')->setName('admin.profile');
|
||||
$app->post('/admin/login', UsersController::class . ':processLoginForm');
|
||||
$app->get('/admin/logout', UsersController::class . ':processLogoutForm')->setName('admin.logout');
|
||||
$app->get('/admin/registration', UsersController::class . ':registration')->setName('admin.registration');
|
||||
$app->post('/admin/registration', UsersController::class . ':processRegistrationForm');
|
||||
$app->post('/admin/login', UsersController::class . ':processLoginForm');
|
||||
|
||||
class UsersController {
|
||||
|
||||
@@ -29,18 +29,29 @@ class UsersController {
|
||||
|
||||
public function login($request, $response, $args)
|
||||
{
|
||||
return $this->container->get('view')->render($response,
|
||||
'plugins/admin/views/templates/users/login.html');
|
||||
if (!Users::isLoggedIn()) {
|
||||
return $this->container->get('view')->render($response,
|
||||
'plugins/admin/views/templates/users/login.html', [
|
||||
'user_is_logged' => Users::isLoggedIn()
|
||||
]);
|
||||
} else {
|
||||
return $response->withRedirect($this->container->get('router')->urlFor('admin.registration'));
|
||||
}
|
||||
}
|
||||
|
||||
public function profile($request, $response, $args)
|
||||
{
|
||||
return $this->container->get('view')->render($response,
|
||||
'plugins/admin/views/templates/users/profile.html', [
|
||||
'username' => Session::get('username'),
|
||||
'rolename' => Session::get('role'),
|
||||
'sidebar_menu_item' => 'profile'
|
||||
]);
|
||||
if (Users::isLoggedIn()) {
|
||||
return $this->container->get('view')->render($response,
|
||||
'plugins/admin/views/templates/users/profile.html', [
|
||||
'username' => Session::get('username'),
|
||||
'rolename' => Session::get('role'),
|
||||
'sidebar_menu_item' => 'profile',
|
||||
'user_is_logged' => 'user_is_logged!'
|
||||
]);
|
||||
} else {
|
||||
return $response->withRedirect($this->container->get('router')->urlFor('admin.login'));
|
||||
}
|
||||
}
|
||||
|
||||
public function processLoginForm($request, $response, $args)
|
||||
@@ -71,8 +82,12 @@ class UsersController {
|
||||
|
||||
public function registration($request, $response, $args)
|
||||
{
|
||||
return $this->view->render($response,
|
||||
'plugins/admin/views/templates/users/registration.html');
|
||||
if (!Users::isLoggedIn()) {
|
||||
return $this->view->render($response,
|
||||
'plugins/admin/views/templates/users/registration.html');
|
||||
} else {
|
||||
return $response->withRedirect($this->container->get('router')->urlFor('admin.login'));
|
||||
}
|
||||
}
|
||||
|
||||
public function processRegistrationForm($request, $response, $args)
|
||||
@@ -106,7 +121,7 @@ class Users
|
||||
return ($users && count($users) > 0) ? true : false;
|
||||
}
|
||||
|
||||
public static function isLoggedIn()
|
||||
public static function isLoggedIn() : bool
|
||||
{
|
||||
return (Session::exists('role') && Session::get('role') == 'admin') ? true : false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user