Commit 1c28c588 authored by kanellov's avatar kanellov

authentication need reimplementation

parent b10ad7cf
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->notPath('data')
->filter(function (SplFileInfo $file) {
if (strstr($file->getPath(), 'compatibility')) {
return false;
}
});
$config = Symfony\CS\Config\Config::create();
$config->level(null);
$config->fixers(
array(
'braces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'function_call_space',
'function_declaration',
'indentation',
'join_function',
'line_after_namespace',
'linefeed',
'lowercase_keywords',
'parenthesis',
'multiple_use',
'method_argument_space',
'object_operator',
'php_closing_tag',
'psr0',
'remove_lines_between_uses',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
'unused_use',
'visibility',
'whitespacy_lines',
'ternary_spaces',
'align_double_arrow',
'align_equals',
'concat_with_spaces',
'ordered_use',
'short_array_syntax',
'single_array_no_trailing_comma',
'multiline_array_trailing_comma',
'spaces_cast',
'return',
'double_arrow_multiline_whitespaces',
)
);
$config->finder($finder);
return $config;
\ No newline at end of file
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -11,7 +12,9 @@ return [
'modules' => [
'module/authentication/bootstrap.php',
'module/authorization/bootstrap.php',
'module/sch_ldap/bootstrap.php',
'module/sch_sso/bootstrap.php',
'module/sch_auto_create/bootstrap.php',
'module/application/bootstrap.php',
],
'cache_config' => 'data/cache/config/settings.php',
......
<?php
return [
'determineRouteBeforeAppMiddleware' => true,
'displayErrorDetails' => true,
'db' => [
'dsn' => 'sqlite:' . __DIR__ . '/../data/tmp/db.sq3',
'user' => null,
'pass' => null,
'options' => [
],
],
];
<?php
return [
'acl' => [
'default_role' => 'guest',
'roles' => [
'guest' => [],
'user' => [],
'admin' => ['user'],
],
'resoures' => [],
'guards' => [
'resources' => [],
'callables' => [],
'routes' => [
['/', ['guest', 'user'], ['get']],
['/user/login', ['guest'], ['get', 'post']],
['/user/logout', ['user'], ['get']],
['/school', ['guest', 'user'], ['get']],
['/school/labs', ['guest', 'user'], ['get']],
['/school/staff', ['guest', 'user'], ['get']],
['/school/assets', ['guest', 'user'], ['get']],
],
],
],
];
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return [
'ldap' => [
'host' => '',
'username' => '',
'password' => '',
'baseDn' => '',
'port' => 389,
'useSsl' => false,
'bindRequiresDn' => true,
'accountCanonicalForm' => null,
'accountDomainName' => null,
'accountDomainNameShort' => null,
'accountFilterFormat' => null,
'allowEmptyPassword' => false,
'useStartTls' => false,
'optReferrals' => false,
'tryUsernameSplit' => true,
'networkTimeout' => null,
],
'sso' => [
'allowed' => '&(physicaldeliveryofficename=ΕΠΙΣΗΜΟΣ ΛΟΓΑΡΙΑΣΜΟΣ)(umdobject=account)',
],
];
\ No newline at end of file
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -22,22 +23,22 @@ return [
'info' => [
'label' => 'Πληροφορίες',
'route' => 'school',
'icon' => 'info'
'icon' => 'info',
],
'staff' => [
'label' => 'Εκπαιδευτικοί',
'route' => 'school.staff',
'icon' => 'users'
'icon' => 'users',
],
'labs' => [
'label' => 'Χώροι',
'route' => 'school.labs',
'icon' => 'building-o'
'icon' => 'building-o',
],
'assets' => [
'label' => 'Εξοπλισμός',
'route' => 'school.assets',
'icon' => 'tv'
'icon' => 'tv',
],
],
],
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -13,9 +14,9 @@ return function (Slim\App $app) {
$container['autoloader']->addPsr4('GrEduLabs\\Application\\', __DIR__ . '/src');
$container['view'] = function($c) {
$container['view'] = function ($c) {
$settings = $c['settings'];
$view = new Slim\Views\Twig(
$view = new Slim\Views\Twig(
$settings['view']['template_path'],
$settings['view']['twig']
);
......@@ -24,11 +25,7 @@ return function (Slim\App $app) {
$c['request']->getUri()
));
$view->addExtension(new GrEduLabs\Application\Twig\Extension\Navigation(
$settings['navigation'],
$c->get('router'),
$c->get('request')
));
$view->addExtension($c[GrEduLabs\Application\Twig\Extension\Navigation::class]);
$view->addExtension(new Knlv\Slim\Views\TwigMessages(
$c['flash']
));
......@@ -36,12 +33,20 @@ return function (Slim\App $app) {
return $view;
};
$container[GrEduLabs\Application\Twig\Extension\Navigation::class] = function ($c) {
return new GrEduLabs\Application\Twig\Extension\Navigation(
$c['settings']['navigation'],
$c['router'],
$c['request']
);
};
$container['flash'] = function ($c) {
return new \Slim\Flash\Messages();
};
$container['logger'] = function ($c) {
$settings = $c['settings'];
$settings = $c['settings'];
$logger = new Monolog\Logger($settings['logger']['name']);
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushHandler(new Monolog\Handler\RotatingFileHandler(
......@@ -57,6 +62,10 @@ return function (Slim\App $app) {
return new GrEduLabs\Application\Authentication\RedbeanListener();
};
$container['csrf'] = function ($c) {
return new \Slim\Csrf\Guard();
};
$events = $container['events'];
$events('on', 'bootstrap', function () use ($container) {
session_name('GrEduLabs');
......@@ -65,17 +74,20 @@ return function (Slim\App $app) {
// setup RedbeanPHP
RedBeanPHP\R::setup(
$container['settings']['db']['dsn'],
$container['settings']['db']['dsn'],
$container['settings']['db']['user'],
$container['settings']['db']['pass']
);
}, 1000000);
$events('on', 'authenticate', $container['authenticate_redbean_listener']);
$container['csrf'] = function ($c) {
return new \Slim\Csrf\Guard();
};
define('REDBEAN_MODEL_PREFIX', 'GrEduLabs\\Application\\Model\\');
}, 10000000);
$events('on', 'bootstrap', function () use ($container) {
$container['router']->getNamedRoute('user.login')->add('csrf');
});
$events('on', 'authenticate', $container['authenticate_redbean_listener']);
$container['GrEduLabs\\Application\\Action\\Index'] = function ($c) {
return new GrEduLabs\Application\Action\Index($c['view']);
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -15,7 +16,6 @@ use Slim\Views\Twig;
class Index
{
protected $view;
public function __construct(Twig $view)
......@@ -28,19 +28,19 @@ class Index
return $this->view->render($res, 'app-form/index.twig', [
'assets' => [
[
'typeName' => 'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 1',
'quantity' => 2,
'typeName' => 'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 1',
'quantity' => 2,
],
[
'typeName' => 'LAPTOP',
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'quantity' => 1,
'typeName' => 'LAPTOP',
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'quantity' => 1,
],
[
'typeName' => 'ΠΛΗΚΤΡΟΛΟΓΙΟ',
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'quantity' => 10,
'typeName' => 'ΠΛΗΚΤΡΟΛΟΓΙΟ',
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'quantity' => 10,
],
],
'for_choices' => [
......@@ -59,26 +59,26 @@ class Index
],
'lab_choices' => [
[
'value' => 1,
'label' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 1',
'value' => 1,
'label' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 1',
],
[
'value' => 2,
'label' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'value' => 2,
'label' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
],
],
'type_choices' => [
[
'value' => 1,
'label' => 'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',
'value' => 1,
'label' => 'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',
],
[
'value' => 3,
'label' => 'LAPTOP',
'value' => 3,
'label' => 'LAPTOP',
],
[
'value' => 2,
'label' => 'ΠΛΗΚΤΡΟΛΟΓΙΟ',
'value' => 2,
'label' => 'ΠΛΗΚΤΡΟΛΟΓΙΟ',
],
],
]);
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -14,7 +15,6 @@ use Slim\Http\Response;
class SubmitAppForm
{
public function __invoke(Request $req, Response $res, array $args = [])
{
$params = $req->getParams();
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -21,7 +22,8 @@ class Index
protected $view;
/**
* Constructor
* Constructor.
*
* @param Twig $view
*/
public function __construct(Twig $view)
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -15,7 +16,6 @@ use Slim\Views\Twig;
class Assets
{
protected $view;
public function __construct(Twig $view)
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -15,7 +16,6 @@ use Slim\Views\Twig;
class Index
{
protected $view;
public function __construct(Twig $view)
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -15,7 +16,6 @@ use Slim\Views\Twig;
class Labs
{
protected $view;
public function __construct(Twig $view)
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -15,7 +16,6 @@ use Slim\Views\Twig;
class Staff
{
protected $view;
public function __construct(Twig $view)
......
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -17,7 +18,6 @@ class RedbeanListener
return false;
}
$stop();
}
}
\ No newline at end of file
}
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\Application\Model;
use RedBeanPHP\SimpleModel;
class User extends SimpleModel
{
}
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -56,7 +57,7 @@ class Navigation extends Twig_Extension
$this->currentRole = $currentRole;
}
/**
/**
* Extension name.
*
* @return string
......@@ -78,6 +79,20 @@ class Navigation extends Twig_Extension
];
}
public function setAcl(AclInterface $acl)
{
$this->acl = $acl;
return $this;
}
public function setCurrentRole($role)
{
$this->currentRole = $role;
return $this;
}
/**
*
*/
......@@ -107,7 +122,6 @@ class Navigation extends Twig_Extension
$path = parse_url($page['href'], PHP_URL_PATH);
$page['active'] = ($path !== '/' && 0 === strpos($this->request->getUri()->getPath(), $path));
if (isset($page['pages']) && is_array($page['pages'])) {
$page['pages'] = array_filter(array_map($prepare, $page['pages']), $aclFilter);
}
......
......@@ -3,8 +3,8 @@
<div class="jumbotron">
<h1>Σχολικά εργαστήρια</h1>
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam vel volutpat diam, vitae consectetur libero. Sed et sem et nisi aliquet condimentum. Morbi id magna iaculis, dictum lectus vitae, suscipit nisl. Proin molestie dolor vitae pulvinar tristique. Integer egestas varius lorem id scelerisque. Praesent velit metus, egestas facilisis iaculis id, auctor nec mi. Suspendisse ultrices laoreet justo eget viverra.</p>
{#{% if not identity() %}
{% if not identity() %}
<p><a class="btn btn-lg btn-success" href="{{ path_for('user.login') }}" role="button">Σύνδεση</a></p>
{% endif %}#}
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -10,7 +11,7 @@
return function (Slim\App $app) {
$container = $app->getContainer();
$events = $container['events'];
$events = $container['events'];
$container['autoloader']->addPsr4('GrEduLabs\\Authentication\\', __DIR__ . '/src');
......@@ -29,12 +30,16 @@ return function (Slim\App $app) {
);
};
$container['authentication_identity_class'] = function ($c) {
return GrEduLabs\Authentication\Identity::class;
};
$events('on', 'bootstrap', function () use ($container) {
$container->extend('view', function ($view, $c) {
$view->addExtension(new GrEduLabs\Authentication\Twig\Extension\Identity(
$c['authentication_service']
));
return $view;
});
});
......@@ -65,9 +70,4 @@ return function (Slim\App $app) {
$this->get('/logout', 'GrEduLabs\\Authentication\\Action\\User\\Logout')
->setName('user.logout');
});
$events = $container['events'];
$events('on', 'bootstrap', function () use ($container) {
$container['router']->getNamedRoute('user.login')->add('csrf');
});
};
\ No newline at end of file
};
<?php
/**
* gredu_labs
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
......@@ -14,9 +15,9 @@ use Slim\Flash\Messages;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Adapter\ValidatableAdapterInterface;
use Zend\Authentication\AuthenticationService;
class Login
{
......@@ -46,11 +47,12 @@ class Login
protected $successUrl;
/**
* Constructor
* @param Twig $view
* Constructor.
*
* @param Twig $view
* @param AuthenticationService $authService
* @param AdapterInterface $authAdapter
* @param Messages $flash
* @param AdapterInterface $authAdapter
* @param Messages $flash
*/
public function __construct(
Twig $view,
......@@ -67,16 +69,16 @@ class Login
}
public function __invoke(Request $req, Response $res)
{
{
if ($req->isPost()) {
$adapter = $this->authService->getAdapter();
if ($adapter instanceof ValidatableAdapterInterface) {
$adapter->setIdentity($req->getParam('identity'));
$adapter->setCredential($req->getParam('credential'));
}
$result = $this->authService->authenticate($adapter);
if (!$result->isValid()) {
$this->flash->addMessage('danger', reset($result->getMessages()));
......@@ -84,7 +86,7 @@ class Login
}