Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
#14: Make user interface independent of DoctrineBundle
Browse files Browse the repository at this point in the history
- Controller\GuardStatsController no longer uses annotations
- Resources/config/routing.yml now defines each route individually
- Resources/config/services.yml added param metaclass_auth_guard.ui.statistics.controller
- Resources/doc/Installation.md
    9. The user interface for user administrators
        added info about the controller template

Make web based user interface more extendable:
- DependencyInjection\Configuration::getConfigTreeBuilder added ui.statistics.template
- DependencyInjection\MetaclassAuthenticationGuardExtension::load now sets param:
      metaclass_auth_guard.ui.statistics.template
- Resources/config/services.yml
    . corrected the param name for the StatsPeriod formType
    . removed the template param
- Resources/doc/Installation.md
    9. The user interface for user administrators
        removed info about the template parameter
    12. Datetime format used by the web based user interface
        title added
    13. Template used by the web based user interface for user administrators
        added
  • Loading branch information
metaclass-nl committed Dec 25, 2015
1 parent b2bb71c commit 7888eb5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
14 changes: 6 additions & 8 deletions Controller/GuardStatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Metaclass\AuthenticationGuardBundle\Service\UsernamePasswordFormAuthenticationGuard;
use Metaclass\AuthenticationGuardBundle\Form\Type\StatsPeriodType;
Expand All @@ -30,7 +27,7 @@ class GuardStatsController extends Controller {
protected $translateRelativeDateArray;

/**
* @Route("/statistics", name="Guard_statistics")
* Route("/statistics", name="Guard_statistics")
*/
public function statisticsAction()
{
Expand Down Expand Up @@ -68,7 +65,7 @@ public function statisticsAction()
}

/**
* @Route("/history/{ipAddress}", name="Guard_history", requirements={"ipAddress" = "[^/]+"})
* Route("/history/{ipAddress}", name="Guard_history", requirements={"ipAddress" = "[^/]+"})
*/
public function historyAction($ipAddress)
{
Expand Down Expand Up @@ -105,8 +102,9 @@ public function historyAction($ipAddress)
$this->container->getParameter('metaclass_auth_guard.statistics.template'),
$params);
}
/**
* @Route("/statistics/{username}", name="Guard_statisticsByUserName", requirements={"username" = "[^/]*"})

/**
* Route("/statistics/{username}", name="Guard_statisticsByUserName", requirements={"username" = "[^/]*"})
*/
public function statisticsByUserNameAction($username)
{
Expand Down Expand Up @@ -180,7 +178,7 @@ protected function addStatsPeriodForm(&$params, $governor, $label, $limitFrom=nu
$labels = array('From' => 'StatsPeriod.From', 'Until' => 'StatsPeriod.Until');
$historyLimit = new \DateTime("$governor->dtString - $governor->keepCountsFor");

$formTypeClass = $this->container->getParameter('metaclass_auth_guard.statistics.StatsPeriod.formType');
$formTypeClass = $this->container->getParameter('metaclass_auth_guard.ui.StatsPeriod.formType');
if (!class_exists($formTypeClass)) {
throw new RuntimeException("value of metaclass_auth_guard.statistics.StatsPeriod.formType is not a class: '$formTypeClass'");
}
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('dateTimeFormat')->defaultValue('SHORT')->end()
->arrayNode('statistics')
->addDefaultsIfNotSet()
->children()
->scalarNode('template')->defaultValue('MetaclassAuthenticationGuardBundle:Guard:statistics.html.twig')->end()
->end()
->end()
->end()
->end()
->arrayNode('tresholds_governor_params')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('metaclass_auth_guard.db_connection.name', $config['db_connection']['name']);
$container->setParameter('metaclass_auth_guard.ui.dateTimeFormat', $config['ui']['dateTimeFormat']);
$container->setParameter('metaclass_auth_guard.statistics.template', $config['ui']['statistics']['template']);
$container->setParameter('metaclass_auth_guard.tresholds_governor_params', $config['tresholds_governor_params']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down
19 changes: 15 additions & 4 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
# otherwise anybody will be able to see the user names, ip addresses, date, time and more
# of all login attemtps!!!
#
Guard:
resource: "@MetaclassAuthenticationGuardBundle/Controller/GuardStatsController.php"
type: annotation
prefix: /guard
Guard_statistics:
path: /statistics
defaults: { _controller: "%metaclass_auth_guard.ui.statistics.controller%:statistics" }

Guard_history:
path: /history/{ipAddress}
defaults: { _controller: "%metaclass_auth_guard.ui.statistics.controller%:history" }
requirements:
ipAddress: "[^/]+"

Guard_statisticsByUserName:
path: /statistics/{username}
defaults: { _controller: "%metaclass_auth_guard.ui.statistics.controller%:statisticsByUserName" }
requirements:
username: "[^/]*"
5 changes: 3 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ parameters:
metaclass_auth_guard.gateway.class: "Metaclass\TresholdsGovernor\Gateway\DbalGateway"
metaclass_auth_guard.tresholds_governor.class: "Metaclass\TresholdsGovernor\Service\TresholdsGovernor"
metaclass_auth_guard.authentication.listener.form.class: "Metaclass\AuthenticationGuardBundle\Service\UsernamePasswordFormAuthenticationGuard"
metaclass_auth_guard.statistics.StatsPeriod.formType: "Metaclass\AuthenticationGuardBundle\Form\Type\StatsPeriodType"
metaclass_auth_guard.statistics.template: "MetaclassAuthenticationGuardBundle:Guard:statistics.html.twig"

metaclass_auth_guard.ui.statistics.controller: "MetaclassAuthenticationGuardBundle:GuardStats"
metaclass_auth_guard.ui.StatsPeriod.formType: "Metaclass\AuthenticationGuardBundle\Form\Type\StatsPeriodType"

services:

Expand Down
33 changes: 20 additions & 13 deletions Resources/doc/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Installation
randomSleepingNanosecondsMax: 99999
ui:
dateTimeFormat: "SHORT"
statistics:
template: "MetaclassAuthenticationGuardBundle:Guard:statistics.html.twig"
```

8. From cron or so you may garbage-collect/pack stored RequestCounts:
Expand All @@ -121,7 +123,7 @@ Installation
```yml
metaclass_auth_guard:
resource: "@MetaclassAuthenticationGuardBundle/Resources/config/routing.yml"
prefix: /
prefix: /guard
```
And add the path of the user interface to your firewall in app/conf/security.yml:
```yml
Expand All @@ -138,18 +140,9 @@ Installation
- guard/statistics/username (replace 'username' by an actual username)
The default template assumes you have base.html.twig still in app/Resources/views.
In an actual application you typically use a template of your own that extends your own layout
and includes MetaclassAuthenticationGuardBundle:Guard:statistics_content.html.twig .
To change the template used override the parameter metaclass_auth_guard.statistics.template
in your applications configuration.
If your layout requires more parameters you probably want to use your own subclass
of GuardStatsController. For this you may override the route(s) from Resources/config/routing.yml
in your applications routing.yml after the metaclass_auth_guard resource configuration
or replace the resource configuration entirely.
If you want to use other datetime widgets you may override the parameter
metaclass_auth_guard.statistics.StatsPeriod.formType to refer to a class of your own.
Resources/config/services.yml defines parameters for the controller class and
the StatsPeriod formtype. You may override them to use your own (sub)classes.
Currently the web based user interface only supports English and Dutch.
Please clone the Bundle on Github and add your own language translation!
Expand Down Expand Up @@ -289,7 +282,8 @@ Configurations
details a random between 0 and this value is added by ::sleepUntilSinceInit (which
is called by ::sleepUntilFixedExecutionTime).

12.
12. Datetime format used by the web based user interface

ui:
dateTimeFormat

Expand All @@ -307,6 +301,19 @@ Configurations
transformer you may like (but that will not be used by the DateTimeType widgets in the
Period form so you may want to set your own form type too).

13. Template used by the web based user interface for user administrators

ui:
statistics:
template

Bundlename:views subfolder:template filename

In an actual application you typically use a template of your own that extends your own layout
and includes MetaclassAuthenticationGuardBundle:Guard:statistics_content.html.twig.

The default template assumes you have base.html.twig still in app/Resources/views.

Notes

- releasing is possible for a username in general, an IP address in general, or for the combination of a username with an ip address
Expand Down
23 changes: 22 additions & 1 deletion Resources/doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,27 @@ Make web based user interface more extendable:
- Resources/config/services.yml added parameters metaclass_auth_guard.statistics.StatsPeriod.formType
- Controller\GuardStatsController::addStatsPeriodForm now uses parameter metaclass_auth_guard.statistics.StatsPeriod.formType
::initDateFormatAndPattern may be overridden for setting locale dependent (custom) patterns

comitted, pushed, published, tagged v0.3.1
----------------------------------------------------
#14: Make user interface independent of DoctrineBundle
- Controller\GuardStatsController no longer uses annotations
- Resources/config/routing.yml now defines each route individually
- Resources/config/services.yml added param metaclass_auth_guard.ui.statistics.controller
- Resources/doc/Installation.md
9. The user interface for user administrators
added info about the controller template

Make web based user interface more extendable:
- DependencyInjection\Configuration::getConfigTreeBuilder added ui.statistics.template
- DependencyInjection\MetaclassAuthenticationGuardExtension::load now sets param:
metaclass_auth_guard.ui.statistics.template
- Resources/config/services.yml
. corrected the param name for the StatsPeriod formType
. removed the template param
- Resources/doc/Installation.md
9. The user interface for user administrators
removed info about the template parameter
12. Datetime format used by the web based user interface
title added
13. Template used by the web based user interface for user administrators
added

0 comments on commit 7888eb5

Please sign in to comment.