diff --git a/config/app.config.php b/config/app.config.php index ebeed59759b73421e0fa78252febd9a4bc450100..3ecfb96dd3e0968e1dbf174508ecad71d3437190 100644 --- a/config/app.config.php +++ b/config/app.config.php @@ -20,6 +20,7 @@ return [ 'module/sch_inventory/bootstrap.php', 'module/sch_sync/bootstrap.php', 'module/schools/bootstrap.php', + 'module/application_form/bootstrap.php', ], 'cache_config' => 'data/cache/config/settings.php', ]; diff --git a/config/settings/acl.global.php b/config/settings/acl.global.php index 6d41f58718f85b134898b9a041fe1cbd6aace98b..74f6fa9a8f760853c7c7ba6124ce4d5beaad3c40 100644 --- a/config/settings/acl.global.php +++ b/config/settings/acl.global.php @@ -22,6 +22,12 @@ return [ 'callables' => [], 'routes' => [ ['/', ['guest', 'user'], ['get']], + ['/school', ['school'], ['get']], + ['/school/labs', ['school'], ['get', 'post']], + ['/school/staff', ['school'], ['get', 'post', 'delete']], + ['/school/assets', ['school'], ['get', 'post', 'delete']], + ['/school/labs/attachment', ['school'], ['get', 'delete']], + ['/application-form', ['school'], ['get', 'post']], ], ], ], diff --git a/config/settings/assets_manager.global.php b/config/settings/assets_manager.global.php index 4538fcd688a50576e68e3a920239271a9a5e838f..4a2242670dacfd780bc46544a61dbeeb834a419a 100644 --- a/config/settings/assets_manager.global.php +++ b/config/settings/assets_manager.global.php @@ -12,6 +12,7 @@ return [ 'web_dir' => __DIR__ . '/../../public', 'paths' => [ 'module/schools/public', + 'module/application_form/public', ], ], ]; diff --git a/config/settings/schools.global.php b/config/settings/schools.global.php index 0adcbf6ddb917e1ed1eaf56425784a0a7763a679..01dfb4452b33a3232cf60ba1bc61e3b1e9cd1cbb 100644 --- a/config/settings/schools.global.php +++ b/config/settings/schools.global.php @@ -8,17 +8,6 @@ */ return [ - 'acl' => [ - 'guards' => [ - 'routes' => [ - ['/school', ['school'], ['get']], - ['/school/labs', ['school'], ['get', 'post']], - ['/school/staff', ['school'], ['get', 'post', 'delete']], - ['/school/assets', ['school'], ['get', 'post', 'delete']], - ['/school/labs/attachment', ['school'], ['get', 'delete']], - ], - ], - ], 'schools' => [ 'file_upload' => [ 'tmp_path' => 'data/tmp', diff --git a/module/application/bootstrap.php b/module/application/bootstrap.php index 3c98e5a0314729a42d63608da284052332c1675a..817d27d88e545c1a409ce5573f9026250ce8d6ab 100644 --- a/module/application/bootstrap.php +++ b/module/application/bootstrap.php @@ -79,6 +79,13 @@ return function (Slim\App $app) { return new \Slim\Csrf\Guard(); }; + $container[GrEduLabs\Application\Middleware\AddCsrfToView::class] = function ($c) { + return new GrEduLabs\Application\Middleware\AddCsrfToView( + $c->get('view'), + $c->get('csrf') + ); + }; + $container['GrEduLabs\\Application\\Action\\Index'] = function ($c) { return new GrEduLabs\Application\Action\Index($c['view']); }; diff --git a/module/application/src/Action/AppForm/Index.php b/module/application/src/Action/AppForm/Index.php deleted file mode 100644 index 42dae47d16350291b0a1f72b96cdb0a2b8a9e73c..0000000000000000000000000000000000000000 --- a/module/application/src/Action/AppForm/Index.php +++ /dev/null @@ -1,86 +0,0 @@ -<?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\Action\AppForm; - -use Slim\Http\Request; -use Slim\Http\Response; -use Slim\Views\Twig; - -class Index -{ - protected $view; - - public function __construct(Twig $view) - { - $this->view = $view; - } - - public function __invoke(Request $req, Response $res, array $args = []) - { - return $this->view->render($res, 'app-form/index.twig', [ - 'assets' => [ - [ - 'typeName' => 'ΞΞΞΞ€ΞΞΞ Ξ‘ΞΞΞΞΞΞΞ£', - 'labName' => 'ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ Ξ ΞΞΞ‘ΞΞ¦/ΞΞΞ£ 1', - 'quantity' => 2, - ], - [ - 'typeName' => 'LAPTOP', - 'labName' => 'ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ Ξ ΞΞΞ‘ΞΞ¦/ΞΞΞ£ 2', - 'quantity' => 1, - ], - [ - 'typeName' => 'Ξ ΞΞΞ΀ΑΞΞΞΞΞΞ', - 'labName' => 'ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ Ξ ΞΞΞ‘ΞΞ¦/ΞΞΞ£ 2', - 'quantity' => 10, - ], - ], - 'for_choices' => [ - [ - 'label' => 'Ξ ΞΞΞ‘ΞΞ£ ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ', - 'value' => 'Ξ ΞΞΞ‘ΞΞ£ ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ', - ], - [ - 'label' => 'ΞΞΞΞΞΞΞΞΣΠΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞΞ₯', - 'value' => 'ΞΞΞΞΞΞΞΞΣΠΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞΞ₯', - ], - [ - 'label' => 'ΞΞΞΞ΀ΠΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ', - 'value' => 'ΞΞΞΞ΀ΠΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ', - ], - ], - 'lab_choices' => [ - [ - 'value' => 1, - 'label' => 'ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ Ξ ΞΞΞ‘ΞΞ¦/ΞΞΞ£ 1', - ], - [ - 'value' => 2, - 'label' => 'ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ Ξ ΞΞΞ‘ΞΞ¦/ΞΞΞ£ 2', - ], - ], - 'type_choices' => [ - [ - 'value' => 1, - 'label' => 'ΞΞΞΞ€ΞΞΞ Ξ‘ΞΞΞΞΞΞΞ£', - ], - [ - 'value' => 3, - 'label' => 'LAPTOP', - ], - [ - 'value' => 2, - 'label' => 'Ξ ΞΞΞ΀ΑΞΞΞΞΞΞ', - ], - ], - ]); - } -} diff --git a/module/application/src/Middleware/AddCsrfToView.php b/module/application/src/Middleware/AddCsrfToView.php new file mode 100644 index 0000000000000000000000000000000000000000..7a1df0e756d688470cdc177b472f71972b30873d --- /dev/null +++ b/module/application/src/Middleware/AddCsrfToView.php @@ -0,0 +1,46 @@ +<?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\Middleware; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Slim\Csrf\Guard; +use Slim\Views\Twig; + +class AddCsrfToView +{ + private $view; + + private $csrf; + + public function __construct(Twig $view, Guard $csrf) + { + $this->view = $view; + $this->csrf = $csrf; + } + + public function __invoke(ServerRequestInterface $req, ResponseInterface $res, callable $next) + { + $nameKey = $this->csrf->getTokenNameKey(); + $valueKey = $this->csrf->getTokenValueKey(); + $name = $req->getAttribute($nameKey); + $value = $req->getAttribute($valueKey); + + $this->view['csrf'] = [ + 'name_key' => $nameKey, + 'value_key' => $valueKey, + 'name' => $name, + 'value' => $value, + ]; + + return $next($req, $res); + } +} diff --git a/module/application_form/bootstrap.php b/module/application_form/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..a5dc9357cd8bc3fa95b9d8152bee208a68cb6a2c --- /dev/null +++ b/module/application_form/bootstrap.php @@ -0,0 +1,65 @@ +<?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 function (Slim\App $app) { + $container = $app->getContainer(); + $events = $container['events']; + + $events('on', 'app.autoload', function ($stop, $autoloader) { + $autoloader->addPsr4('GrEduLabs\\ApplicationForm\\', __DIR__ . '/src/'); + }); + + $events('on', 'app.services', function ($stop, $container) { + + $container[GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class] = function ($c) { + return new GrEduLabs\ApplicationForm\Service\ApplicationFormService(); + }; + + $container[GrEduLabs\ApplicationForm\InputFilter\ApplicationForm::class] = function ($c) { + return new GrEduLabs\ApplicationForm\InputFilter\ApplicationForm( + $c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class), + $c->get(GrEduLabs\Schools\Service\SchoolServiceInterface::class), + $c->get(GrEduLabs\ApplicationForm\InputFilter\ApplicationFormItemCollection::class) + ); + }; + + $container[GrEduLabs\ApplicationForm\InputFilter\ApplicationFormItem::class] = function ($c) { + return new GrEduLabs\ApplicationForm\InputFilter\ApplicationFormItem( + $c->get(GrEduLabs\Schools\Service\LabServiceInterface::class), + $c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class) + ); + }; + + $container[GrEduLabs\ApplicationForm\InputFilter\ApplicationFormItemCollection::class] = function ($c) { + return new GrEduLabs\ApplicationForm\InputFilter\ApplicationFormItemCollection( + $c->get(GrEduLabs\ApplicationForm\InputFilter\ApplicationFormItem::class) + ); + }; + + $container[GrEduLabs\ApplicationForm\Action\ApplicationForm::class] = function ($c) { + return new GrEduLabs\ApplicationForm\Action\ApplicationForm( + $c->get('view'), + $c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class), + $c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class), + $c->get(GrEduLabs\ApplicationForm\InputFilter\ApplicationForm::class) + ); + }; + }); + + $events('on', 'app.bootstrap', function ($stop, $app, $container) { + $container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates'); + + $app->map(['get', 'post'], '/application-form', GrEduLabs\ApplicationForm\Action\ApplicationForm::class) + ->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class) + ->add(GrEduLabs\Application\Middleware\AddCsrfToView::class) + ->add('csrf') + ->setName('application_form'); + }); +}; diff --git a/public/js/app-form/index.js b/module/application_form/public/js/application_form/index.js similarity index 100% rename from public/js/app-form/index.js rename to module/application_form/public/js/application_form/index.js diff --git a/module/application_form/src/Action/ApplicationForm.php b/module/application_form/src/Action/ApplicationForm.php new file mode 100644 index 0000000000000000000000000000000000000000..f464aa88401e08b51f29864b28851f4ca1d10230 --- /dev/null +++ b/module/application_form/src/Action/ApplicationForm.php @@ -0,0 +1,86 @@ +<?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\ApplicationForm\Action; + +use GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface; +use GrEduLabs\Schools\Service\AssetServiceInterface; +use Slim\Http\Request; +use Slim\Http\Response; +use Slim\Views\Twig; +use Zend\InputFilter\InputFilterInterface; + +class ApplicationForm +{ + /** + * @var Twig + */ + protected $view; + + /** + * + * @var AssetServiceInterface + */ + protected $assetsService; + + /** + * + * @var ApplicationFormServiceInterface + */ + protected $appFormService; + + /** + * + * @var InputFilterInterface + */ + protected $appFormInputFilter; + + + public function __construct( + Twig $view, + AssetServiceInterface $assetsService, + ApplicationFormServiceInterface $appFormService, + InputFilterInterface $appFormInputFilter + ) { + $this->view = $view; + $this->assetsService = $assetsService; + $this->appFormService = $appFormService; + $this->appFormInputFilter = $appFormInputFilter; + } + + public function __invoke(Request $req, Response $res) + { + $school = $req->getAttribute('school'); + if ($req->isPost()) { + $this->appFormInputFilter->setData(array_merge($req->getParams(), [ + 'school_id' => $school->id, + ])); + if ($this->appFormInputFilter->isValid()) { + $data = $this->appFormInputFilter->getValues(); + $this->appFormService->submit($data); + } + var_dump($this->appFormInputFilter->getMessages()); + die('error'); + $this->view['messages'] = $this->appFormInputFilter->getMessages(); + } + + $res = $this->view->render($res, 'application_form/form.twig', [ + 'type_choices' => array_map(function ($category) { + return ['value' => $category['id'], 'label' => $category['name']]; + }, $this->assetsService->getAllItemCategories()), + 'apply_for_choices' => array_map(function ($choice) { + return ['value' => $choice, 'label' => $choice]; + }, $this->appFormService->getApplyForChoices()), + + ]); + + return $res; + } +} diff --git a/module/application_form/src/InputFilter/ApplicationForm.php b/module/application_form/src/InputFilter/ApplicationForm.php new file mode 100644 index 0000000000000000000000000000000000000000..2366851452d49b94c6937b447f4ed3f278a98933 --- /dev/null +++ b/module/application_form/src/InputFilter/ApplicationForm.php @@ -0,0 +1,65 @@ +<?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\ApplicationForm\InputFilter; + +use GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface; +use GrEduLabs\Schools\Service\SchoolServiceInterface; +use Zend\Filter; +use Zend\InputFilter\CollectionInputFilter; +use Zend\InputFilter\Input; +use Zend\InputFilter\InputFilter; +use Zend\Validator; + +class ApplicationForm extends InputFilter +{ + public function __construct( + ApplicationFormServiceInterface $appFormService, + SchoolServiceInterface $schoolService, + CollectionInputFilter $itemsInputFilter + ) { + $schoolId = new Input('school_id'); + $schoolId->setRequired(true) + ->getFilterChain() + ->attach(new Filter\ToInt()); + $schoolId->getValidatorChain() + ->attach(new Validator\NotEmpty()); + + $applyFor = new Input('apply_for'); + $applyFor->setRequired(true) + ->getValidatorChain() + ->attach(new Validator\NotEmpty()) + ->attach(new Validator\InArray([ + 'haystack' => $appFormService->getApplyForChoices(), + ])); + + $newLabPerspective = new Input('new_lab_perspective'); + $newLabPerspective->setRequired(true) + ->getFilterChain() + ->attach(new Filter\ToInt()); + $newLabPerspective->getValidatorChain() + ->attach(new Validator\NotEmpty()) + ->attach(new Validator\InArray([ + 'haystack' => [0, 1], + ])); + + $comments = new Input('comments'); + $comments->setRequired(false) + ->getFilterChain() + ->attach(new Filter\StripTags()) + ->attach(new Filter\StringTrim()); + + $this->add($schoolId) + ->add($applyFor) + ->add($newLabPerspective) + ->add($comments) + ->add($itemsInputFilter, 'items') + ; + } +} diff --git a/module/application_form/src/InputFilter/ApplicationFormItem.php b/module/application_form/src/InputFilter/ApplicationFormItem.php new file mode 100644 index 0000000000000000000000000000000000000000..9218a5499c83b81331385c6cff822ae49688f425 --- /dev/null +++ b/module/application_form/src/InputFilter/ApplicationFormItem.php @@ -0,0 +1,73 @@ +<?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\ApplicationForm\InputFilter; + +use GrEduLabs\Schools\Service\AssetServiceInterface; +use GrEduLabs\Schools\Service\LabServiceInterface; +use Zend\Filter; +use Zend\InputFilter\Input; +use Zend\InputFilter\InputFilter; +use Zend\Validator; + +class ApplicationFormItem extends InputFilter +{ + public function __construct( + LabServiceInterface $labService, + AssetServiceInterface $assetsService + ) { + $lab_id = new Input('lab_id'); + $lab_id->setRequired(true) + ->getFilterChain() + ->attach(new Filter\ToInt()); + $lab_id->getValidatorChain() + ->attach(new Validator\NotEmpty()); + + $itemCategoryId = new Input('itemcategory_id'); + $itemCategoryId->setRequired(true) + ->getFilterChain() + ->attach(new Filter\ToInt()); + $itemCategoryId->getValidatorChain() + ->attach(new Validator\NotEmpty()) + ->attach(new Validator\Callback([ + 'callback' => function ($value) use ($assetsService) { + try { + $type = $assetsService->getItemCategoryById($value); + + return $type && $type['id'] == $value; + } catch (Exception $ex) { + return false; + } + }, + 'message' => 'Ξ ΟΟΟΞΏΟ Ξ΅ΞΎΞΏΟλιΟΞΌΞΏΟ Ξ΄Ξ΅Ξ½ Ρίναι ΞΞ³ΞΊΟ ΟΞΏΟ', + ])); + + $qty = new Input('qty'); + $qty->setRequired(true) + ->getFilterChain() + ->attach(new Filter\ToInt()); + $qty->getValidatorChain() + ->attach(new Validator\NotEmpty()) + ->attach(new Validator\GreaterThan([ + 'min' => 0, + ])); + + $reasons = new Input('reasons'); + $reasons->setRequired(true) + ->getFilterChain() + ->attach(new Filter\StripTags()) + ->attach(new Filter\StringTrim()); + $reasons->getValidatorChain() + ->attach(new Validator\NotEmpty()); + + $this->add($itemCategoryId) + ->add($qty) + ->add($reasons); + } +} diff --git a/module/application_form/src/InputFilter/ApplicationFormItemCollection.php b/module/application_form/src/InputFilter/ApplicationFormItemCollection.php new file mode 100644 index 0000000000000000000000000000000000000000..82c44ab2957683585d1420e2c9549e2c37c01bbe --- /dev/null +++ b/module/application_form/src/InputFilter/ApplicationFormItemCollection.php @@ -0,0 +1,21 @@ +<?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\ApplicationForm\InputFilter; + +use Zend\InputFilter\CollectionInputFilter; +use Zend\InputFilter\InputFilterInterface; + +class ApplicationFormItemCollection extends CollectionInputFilter +{ + public function __construct(InputFilterInterface $itemInputFilter) + { + $this->setInputFilter($itemInputFilter); + } +} diff --git a/module/application_form/src/Service/ApplicationFormService.php b/module/application_form/src/Service/ApplicationFormService.php new file mode 100644 index 0000000000000000000000000000000000000000..a3b6fe41bcc87010abe6c308e3890200c6f5e01b --- /dev/null +++ b/module/application_form/src/Service/ApplicationFormService.php @@ -0,0 +1,36 @@ +<?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\ApplicationForm\Service; + +use RedBeanPHP\R; + +class ApplicationFormService implements ApplicationFormServiceInterface +{ + protected static $applyForChoices = [ + 'Ξ ΞΞΞ‘ΞΞ£ ΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ', + 'ΞΞΞΞΞΞΞΞΣΠΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞΞ₯', + 'ΞΞΞΞ΀ΠΞΞ‘ΞΞΣ΀ΞΞ‘ΞΞ', + ]; + + public function getApplyForChoices() + { + return static::$applyForChoices; + } + + public function submit(array $data) + { + $appForm = R::dispense('applicationform'); + $appForm->school_id = $data['school_id']; + $appForm->apply_for = $data['apply_for']; + $appForm->new_lab_perspective = $data['new_lab_perspective']; + $appForm->comments = $data['comments']; + } +} diff --git a/module/application/src/Action/AppForm/SubmitAppForm.php b/module/application_form/src/Service/ApplicationFormServiceInterface.php similarity index 52% rename from module/application/src/Action/AppForm/SubmitAppForm.php rename to module/application_form/src/Service/ApplicationFormServiceInterface.php index bce09f9c0caa3887aacb1bf87d113ca7399cfa14..3afea06bf8e9b9b873b0d98c4d4f70cbb69f6dd2 100644 --- a/module/application/src/Action/AppForm/SubmitAppForm.php +++ b/module/application_form/src/Service/ApplicationFormServiceInterface.php @@ -8,17 +8,11 @@ * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html */ -namespace GrEduLabs\Action\AppForm; +namespace GrEduLabs\ApplicationForm\Service; -use Slim\Http\Request; -use Slim\Http\Response; - -class SubmitAppForm +interface ApplicationFormServiceInterface { - public function __invoke(Request $req, Response $res, array $args = []) - { - $params = $req->getParams(); - var_dump($params); - die(); - } + public function getApplyForChoices(); + + public function submit(array $data); } diff --git a/module/application/templates/app-form/index.twig b/module/application_form/templates/application_form/form.twig similarity index 65% rename from module/application/templates/app-form/index.twig rename to module/application_form/templates/application_form/form.twig index c2fcd11501e278d16e9d062fce875c794b599775..5be3f3bfa3b186d12f981223e35cb49adc434871 100644 --- a/module/application/templates/app-form/index.twig +++ b/module/application_form/templates/application_form/form.twig @@ -61,50 +61,52 @@ ΞΞ―ΟΞ·ΟΞ· <small>Ξ³ΞΉΞ± Ξ½ΞΞΏ ΡξοΟλιΟΞΌΟ</small> {% endblock %} </h1> - <form method="post" action="{{ path_for('app-form.submit') }}"> + <form method="post" action=""> <div class="form-group"> - <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent pulvinar tincidunt - odio, vel pretium mauris imperdiet at. In tempor fermentum enim, euismod posuere - purus venenatis sit amet. Sed tincidunt, sapien et varius congue, orci urna rutrum - magna, in porttitor tellus ante nec quam. Praesent non ante commodo, ornare tellus + <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent pulvinar tincidunt + odio, vel pretium mauris imperdiet at. In tempor fermentum enim, euismod posuere + purus venenatis sit amet. Sed tincidunt, sapien et varius congue, orci urna rutrum + magna, in porttitor tellus ante nec quam. Praesent non ante commodo, ornare tellus ut, commodo dolor.</p> </div> - <fieldset> - <legend>Ξ₯ΟΞ¬ΟΟΞΏΞ½ ΡξοΟλιΟΞΌΟΟ</legend> - <div class="table-responsive"> - <table class="table table-hover table-striped table-condensed"> - <thead> - <tr> - <th>Ξ§ΟΟΞΏΟ</th> - <th>Ξ€ΟΟΞΏΟ</th> - <th>Ξ Ξ»Ξ�ΞΈΞΏΟ</th> - </tr> - </thead> - <tbody> - {% for asset in assets %} - <tr> - <td>{{ asset.labName }}</td> - <td>{{ asset.typeName }}</td> - <td>{{ asset.quantity }}</td> - </tr> - {% else %} - <tr> - <td colspan="6" class="text-center">ΞΡν ΞΟΡι ΞΊΞ±ΟΞ±ΟΟΟηθΡί ΡξοΟλιΟΞΌΟΟ</td> - </tr> - {% endfor %} - </tbody> - <tfoot> - <tr> - <td colspan="6"></td> - </tr> - </tfoot> - </table> - </div> - </fieldset> - <fieldset> - <legend>ΞΞΞΏΟ Ξ΅ΞΎΞΏΟλιΟΞΌΟΟ</legend> - <div class="form-group" id="items-list"> - <div class="table-responsive"> + <div class="table-responsive"> + <fieldset> + <legend>Ξ₯ΟΞ¬ΟΟΞΏΞ½ ΡξοΟλιΟΞΌΟΟ</legend> + + <table class="table table-hover table-striped table-condensed"> + <thead> + <tr> + <th>Ξ§ΟΟΞΏΟ</th> + <th>Ξ€ΟΟΞΏΟ</th> + <th>Ξ Ξ»Ξ�ΞΈΞΏΟ</th> + </tr> + </thead> + <tbody> + {% for asset in assets %} + <tr> + <td>{{ asset.labName }}</td> + <td>{{ asset.typeName }}</td> + <td>{{ asset.quantity }}</td> + </tr> + {% else %} + <tr> + <td colspan="6" class="text-center">ΞΡν ΞΟΡι ΞΊΞ±ΟΞ±ΟΟΟηθΡί ΡξοΟλιΟΞΌΟΟ</td> + </tr> + {% endfor %} + </tbody> + <tfoot> + <tr> + <td colspan="6"></td> + </tr> + </tfoot> + </table> + + </fieldset> + </div> + <div class="table-responsive"> + <fieldset> + <legend>ΞΞΞΏΟ Ξ΅ΞΎΞΏΟλιΟΞΌΟΟ</legend> + <div class="form-group" id="items-list"> <table class="table table-hover table-striped"> <thead> <tr> @@ -128,12 +130,12 @@ </tfoot> </table> </div> - </div> - </fieldset> + </fieldset> + </div> <fieldset> <legend>ΞΟΞΉΟΞ»ΞΞΏΞ½</legend> - {{ macros.select('for', 'ΞΞ―ΟΞ·ΞΌΞ± ΟΞΏΟ ΟΟΞΏΞ»Ξ΅Ξ―ΞΏΟ Ξ³ΞΉΞ±', for_choices) }} - {{ macros.yesno('new-lab-perspective', 'ΞΟΞ±ΟΞΎΞ· - ΟΟΞΏΞΏΟΟΞΉΞΊΞ� Ξ±Ξ―ΞΈΞΏΟ ΟΞ±Ο Ξ³ΞΉΞ± Ξ΄Ξ·ΞΌΞΉΞΏΟ ΟΞ³Ξ―Ξ± Ξ½ΞΞΏΟ Ξ΅ΟΞ³Ξ±ΟΟΞ·ΟΞ―ΞΏΟ ')}} + {{ macros.select('apply_for', 'ΞΞ―ΟΞ·ΞΌΞ± ΟΞΏΟ ΟΟΞΏΞ»Ξ΅Ξ―ΞΏΟ Ξ³ΞΉΞ±', apply_for_choices) }} + {{ macros.yesno('new_lab_perspective', 'ΞΟΞ±ΟΞΎΞ· - ΟΟΞΏΞΏΟΟΞΉΞΊΞ� Ξ±Ξ―ΞΈΞΏΟ ΟΞ±Ο Ξ³ΞΉΞ± Ξ΄Ξ·ΞΌΞΉΞΏΟ ΟΞ³Ξ―Ξ± Ξ½ΞΞΏΟ Ξ΅ΟΞ³Ξ±ΟΟΞ·ΟΞ―ΞΏΟ ')}} {{ macros.text('comments', 'Ξ£ΟΟλια/Ξ Ξ±ΟΞ±ΟΞ·ΟΞ�ΟΡιΟ', '') }} </fieldset> @@ -141,12 +143,14 @@ <div class="form-group text-center"> <button name="submit" value="submit" type="submit" class="btn btn-lg btn-primary">Ξ₯ΟΞΏΞ²ΞΏΞ»Ξ�</button> </div> + <input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}"> + <input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}"> </form> <script type="text/template" id="app-form-item-row-template"> - <td>{{ macros.itemSelect('lab', 'Ξ§ΟΟΞΏΟ', lab_choices) }}</td> - <td>{{ macros.itemSelect('type', 'Ξ€ΟΟΞΏΟ', type_choices) }}</td> - <td>{{ macros.itemCount('count', 'Ξ Ξ»Ξ�ΞΈΞΏΟ') }}</td> - <td><textarea class="form-control input-sm" rows="1" cols="20" name="items[<%= index %>][comments]" placeholder="ΞΞΉΟιολογία ΟΟΞ�ΟΞ·Ο"></textarea></td> + <td>{{ macros.itemSelect('lab_id', 'Ξ§ΟΟΞΏΟ', lab_choices) }}</td> + <td>{{ macros.itemSelect('itemcategory_id', 'Ξ€ΟΟΞΏΟ', type_choices) }}</td> + <td>{{ macros.itemCount('qty', 'Ξ Ξ»Ξ�ΞΈΞΏΟ') }}</td> + <td><textarea class="form-control input-sm" rows="1" cols="20" name="items[<%= index %>][reasons]" placeholder="ΞΞΉΟιολογία ΟΟΞ�ΟΞ·Ο"></textarea></td> <td><button type="button" class="btn btn-xs text-danger remove-row"> <i class="fa fa-remove"></i> </button</td> @@ -158,5 +162,5 @@ {{ parent() }} <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js"></script> - <script src="{{ base_url }}/js/app-form/index.js"></script> + <script src="{{ base_url }}/js/application_form/index.js"></script> {% endblock %} \ No newline at end of file diff --git a/module/authentication/bootstrap.php b/module/authentication/bootstrap.php index 48f1c3aeb22b82400d5b6df46f18431555ac459f..46d2e626675423a688538af8944c6d2804d62001 100644 --- a/module/authentication/bootstrap.php +++ b/module/authentication/bootstrap.php @@ -103,6 +103,8 @@ return function (Slim\App $app) { $events('on', 'app.bootstrap', function ($stop, $app, $container) { $app->group('/user', function () { $this->map(['GET', 'POST'], '/login', GrEduLabs\Authentication\Action\User\Login::class) + ->add(GrEduLabs\Application\Middleware\AddCsrfToView::class) + ->add('csrf') ->setName('user.login'); $this->get('/logout', GrEduLabs\Authentication\Action\User\Logout::class) diff --git a/module/authentication/src/Action/User/Login.php b/module/authentication/src/Action/User/Login.php index c346302fbfd68680860ae597d4d561e80e97d8c0..21bed300df3ab7c2d7c45ff8fcfb327855ef1b23 100644 --- a/module/authentication/src/Action/User/Login.php +++ b/module/authentication/src/Action/User/Login.php @@ -10,7 +10,6 @@ namespace GrEduLabs\Authentication\Action\User; -use Slim\Csrf\Guard; use Slim\Flash\Messages; use Slim\Http\Request; use Slim\Http\Response; @@ -36,11 +35,6 @@ class Login */ protected $flash; - /** - * @Var Guard - */ - protected $csrf; - /** * @var string */ @@ -58,13 +52,11 @@ class Login Twig $view, AuthenticationService $authService, Messages $flash, - Guard $csrf, $successUrl ) { $this->view = $view; $this->authService = $authService; $this->flash = $flash; - $this->csrf = $csrf; $this->successUrl = $successUrl; } @@ -88,21 +80,6 @@ class Login return $res->withRedirect($this->successUrl); } - return $this->view->render($res, 'user/login.twig', $this->getCsrfData($req)); - } - - private function getCsrfData(Request $req) - { - $nameKey = $this->csrf->getTokenNameKey(); - $valueKey = $this->csrf->getTokenValueKey(); - $name = $req->getAttribute($nameKey); - $value = $req->getAttribute($valueKey); - - return [ - 'csrf_name_key' => $nameKey, - 'csrf_value_key' => $valueKey, - 'csrf_name' => $name, - 'csrf_value' => $value, - ]; + return $this->view->render($res, 'user/login.twig', []); } } diff --git a/module/authentication/templates/user/login.twig b/module/authentication/templates/user/login.twig index 7ec335652162b5fe19127b537a6b581b8cdb5bf2..fb2d8245cf950c8d06ccd55efc56deef2d05a477 100644 --- a/module/authentication/templates/user/login.twig +++ b/module/authentication/templates/user/login.twig @@ -32,8 +32,8 @@ <div class="form-group text-center"> <button name="dologin" type="submit" value="1" class="btn btn-primary">Ξ£ΟνδΡΟΞ·</button> </div> - <input type="hidden" name="{{ csrf_name_key }}" value="{{ csrf_name }}"> - <input type="hidden" name="{{ csrf_value_key }}" value="{{ csrf_value }}"> + <input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}"> + <input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}"> </form> </div> </div> diff --git a/module/sch_sso/templates/user/login.twig b/module/sch_sso/templates/user/login.twig index bddb29c3b925afead69fec02459210f74547352f..98e8e1478757b3dd25d24bd04755eb524a2b8f48 100644 --- a/module/sch_sso/templates/user/login.twig +++ b/module/sch_sso/templates/user/login.twig @@ -42,8 +42,8 @@ <div class="form-group text-center"> <button name="dologin" type="submit" value="1" class="btn btn-primary">Ξ£ΟνδΡΟΞ·</button> </div> - <input type="hidden" name="{{ csrf_name_key }}" value="{{ csrf_name }}"> - <input type="hidden" name="{{ csrf_value_key }}" value="{{ csrf_value }}"> + <input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}"> + <input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}"> </form> </div> </div>