diff --git a/Controller/TosController.php b/Controller/TosController.php index f98227f..5a8b64a 100644 --- a/Controller/TosController.php +++ b/Controller/TosController.php @@ -26,11 +26,11 @@ class TosController extends Controller $em->persist($userTos); } - $tosUrl = $this->container->getParameter('vierbergenlars_tos.tos_url'); + $terms = $this->container->getParameter('vierbergenlars_tos.terms'); $formBuilder = $this->createFormBuilder(); $formBuilder->add('vl_tos', AcceptTosType::class, [ - 'url' => $tosUrl + 'terms' => $terms ]); $formBuilder->add('submit', SubmitType::class, [ @@ -48,8 +48,7 @@ class TosController extends Controller } return [ - 'form' => $form, - 'tos_url' => $tosUrl + 'form' => $form ]; } } \ No newline at end of file diff --git a/DependencyInjection/AuthserverTosExtension.php b/DependencyInjection/AuthserverTosExtension.php index 42eb30a..57f910c 100644 --- a/DependencyInjection/AuthserverTosExtension.php +++ b/DependencyInjection/AuthserverTosExtension.php @@ -31,13 +31,13 @@ class AuthserverTosExtension extends Extension { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - if ($config['url'] !== null) { + if ($config['terms'] !== null) { $servicesDirectory = __DIR__ . '/../Resources/config'; $fileLocator = new FileLocator($servicesDirectory); $xmlLoader = new Loader\XmlFileLoader($container, $fileLocator); $xmlLoader->load('services.xml'); - $container->setParameter('vierbergenlars_tos.tos_url', $config['url']); + $container->setParameter('vierbergenlars_tos.terms', $config['terms']); $container->setParameter('vierbergenlars_tos.tos_version', $config['version']); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index be9ed32..58ef9d5 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1,17 +1,17 @@ . */ @@ -40,7 +40,14 @@ class Configuration implements ConfigurationInterface // @formatter:off $rootNode ->children() - ->scalarNode('url')->defaultNull()->info('Link to the terms of service')->end() + ->arrayNode('terms') + ->prototype('array') + ->children() + ->scalarNode('label')->defaultNull()->info('Label for how the terms are named (terms of service, privacy policy, ...)')->end() + ->scalarNode('url')->defaultNull()->info('Link to the terms of service')->end() + ->end() + ->end() + ->end() ->integerNode('version')->defaultValue(0)->info('Version of the terms of service')->end() ->end(); // @formatter:on diff --git a/EventListener/TosListener.php b/EventListener/TosListener.php index 2914feb..8715d1f 100644 --- a/EventListener/TosListener.php +++ b/EventListener/TosListener.php @@ -21,7 +21,7 @@ use vierbergenlars\AuthserverTosBundle\Form\AcceptTosType; class TosListener implements EventSubscriberInterface { - private $tosUrl; + private $terms; private $tosVersion; @@ -58,9 +58,9 @@ class TosListener implements EventSubscriberInterface ]; } - public function __construct($tosUrl, $tosVersion, EntityManagerInterface $em, TokenStorageInterface $tokenStorage, UrlGeneratorInterface $urlGenerator) + public function __construct($terms, $tosVersion, EntityManagerInterface $em, TokenStorageInterface $tokenStorage, UrlGeneratorInterface $urlGenerator) { - $this->tosUrl = $tosUrl; + $this->terms = $terms; $this->tosVersion = $tosVersion; $this->em = $em; $this->tokenStorage = $tokenStorage; @@ -70,7 +70,7 @@ class TosListener implements EventSubscriberInterface public function onBuildForm(RegistrationFormEvent $event) { $event->getFormBuilder()->add('vl_tos', AcceptTosType::class, [ - 'url' => $this->tosUrl, + 'terms' => $this->terms, 'mapped' => false ]); } diff --git a/Form/AcceptTosType.php b/Form/AcceptTosType.php index cd5c2fa..b87779a 100644 --- a/Form/AcceptTosType.php +++ b/Form/AcceptTosType.php @@ -9,16 +9,32 @@ use Symfony\Component\Validator\Constraints\IsTrue; class AcceptTosType extends AbstractType { + private static function generateTermLink(array $term) + { + return 'the ' . htmlentities($term['label'], ENT_HTML5) . ''; + } + public function buildForm(FormBuilderInterface $builder, array $options) { + $terms = $options['terms']; + if (count($terms) > 1) { + $lastItem = ' and ' . self::generateTermLink(array_pop($terms)); + } else { + $lastItem = ''; + } + $termsString = implode(', ', array_map([ + self::class, + 'generateTermLink' + ], $terms)) . $lastItem; + $builder->add('accept', CheckboxType::class, [ - 'label' => 'I accept the terms of service', + 'label' => 'I accept ' . $termsString, 'attr' => [ 'align_with_widget' => true ], 'constraints' => [ new IsTrue([ - 'message' => 'You must accept the terms of service.' + 'message' => 'You must accept.' ]) ] ]); @@ -31,9 +47,9 @@ class AcceptTosType extends AbstractType */ public function configureOptions(\Symfony\Component\OptionsResolver\OptionsResolver $resolver) { - $resolver->setDefined('url') - ->setRequired('url') - ->addAllowedTypes('url', 'string') + $resolver->setDefined('terms') + ->setRequired('terms') + ->addAllowedTypes('terms', 'array') ->setDefault('label', false); } } \ No newline at end of file diff --git a/README.md b/README.md index be160db..5104b31 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,22 @@ For more details, see the [Authserver plugin documentation](https://github.com/v You can configure the bundle in the authserver `app/config/parameters.yml` file. -Set `tos.url` to a link to your terms of service. +Add a new array key under `tos.terms` for all terms and conditions that you want to add. + +`label` is the name you want to give the terms + +`url` is the URL where the terms are located + Set `tos.version` to the version of your terms of service. This number should be increased every time the terms of service change, so users get prompted to accept the new terms. The version of the latest accepted version is stored per user. If the stored number is lower than the configured version, the user is prompted. + +### Example + +```yaml +tos: + version: 1 + terms: + - title: terms of service + url: http://example.com/tos + - title: privacy policy + url: http://example.com/privacy +``` \ No newline at end of file diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 0a6aa70..5146c42 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -20,7 +20,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - %vierbergenlars_tos.tos_url% + %vierbergenlars_tos.terms% %vierbergenlars_tos.tos_version% diff --git a/Resources/views/Tos/accept.html.twig b/Resources/views/Tos/accept.html.twig index a5549a0..28c48f2 100644 --- a/Resources/views/Tos/accept.html.twig +++ b/Resources/views/Tos/accept.html.twig @@ -1,15 +1,20 @@ {% extends '::base.html.twig' %} +{% block title %}{{ parent() }} - Updated terms and conditions{% endblock %} {% block body %} -
+
-
-
Our terms of service have been updated.
You must accept these terms to be able to continue using the application.
-
-
- -
-
- {{ form(form, {'style': 'horizontal'}) }} +
+
+
+

Updated terms and conditions

+
+
+ Our terms of service have been updated.
You must accept these terms to be able to continue using the application. +
+
+ {{ form(form, {'style': 'horizontal'}) }} +
+