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

Flextype Slim Integration - next round of integration

This commit is contained in:
Awilum
2019-04-16 00:43:49 +03:00
parent d59cf6db9c
commit aec81ecf78

View File

@@ -7,51 +7,43 @@ use Flextype\Component\Session\Session;
use Flextype\Component\Registry\Registry;
use Flextype\Component\Text\Text;
use function Flextype\Component\I18n\__;
use Slim\Http\Request;
use Slim\Http\Response;
use Psr\Container\ContainerInterface;
$app->get('/admin/login', function (Request $request, Response $response, array $args) {
return $this->view->render($response,
'plugins/admin/views/templates/users/login.html');
})->setName('login');
$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->get('/admin/profile', function (Request $request, Response $response, array $args) {
return $this->view->render($response,
'plugins/admin/views/templates/users/profile.html', [
'username' => Session::get('username'),
'rolename' => Session::get('role'),
'sidebar_menu_item' => 'profile'
]);
})->setName('profile');
class UsersController {
$app->get('/admin/logout', function (Request $request, Response $response, array $args) {
Session::destroy();
return $response->withRedirect('/admin');
});
protected $container;
$app->get('/admin/registration', function (Request $request, Response $response, array $args) {
return $this->view->render($response,
'plugins/admin/views/templates/users/registration.html');
})->setName('registration');
$app->post('/admin/registration', function (Request $request, Response $response, array $args) {
if (UsersManager::processRegistrationForm($request->getParsedBody())) {
return $response->withRedirect('admin');
// constructor receives container instance
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
});
$app->post('/admin/login', function (Request $request, Response $response, array $args) {
if (UsersManager::processLoginForm($request->getParsedBody())) {
return $response->withRedirect('admin/entries');
} else {
Notification::set('error', __('admin_message_wrong_username_password'));
public function login($request, $response, $args)
{
return $this->container->get('view')->render($response,
'plugins/admin/views/templates/users/login.html');
}
});
class UsersManager
{
public static function processLoginForm(array $data) : bool
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'
]);
}
public function processLoginForm($request, $response, $args)
{
if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $data['username'] . '.yaml')) {
@@ -61,17 +53,29 @@ class UsersManager
Session::set('username', $user_file['username']);
Session::set('role', $user_file['role']);
return true;
return $response->withRedirect('admin/entries');
} else {
return false;
//Notification::set('error', __('admin_message_wrong_username_password'));
}
} else {
return false;
//Notification::set('error', __('admin_message_wrong_username_password'));
}
}
public static function processRegistrationForm(array $data) : bool
public function processLogoutForm($request, $response, $args)
{
Session::destroy();
return $response->withRedirect('/admin');
}
public function registration($request, $response, $args)
{
return $this->view->render($response,
'plugins/admin/views/templates/users/registration.html');
}
public function processRegistrationForm($request, $response, $args)
{
if (!Filesystem::has($_user_file = PATH['site'] . '/accounts/' . Text::safeString($data['username']) . '.yaml')) {
if (Filesystem::write(
@@ -81,15 +85,18 @@ class UsersManager
'email' => $data['email'],
'role' => 'admin',
'state' => 'enabled']))) {
return true;
return $response->withRedirect('admin/entries');
} else {
return false;
//return false;
}
} else {
return false;
//return false;
}
}
}
class Users
{
public static function isUsersExists() : bool
{
// Get Users Profiles