Commit c23552c0 by Julien Jorry

Update login/register/reset form + debug change password + unit test with phpunit

parent d89562de
......@@ -8,7 +8,7 @@ if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-php
$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
App\Kernel::bootstrapEnv('test');
$classLoader->unregister();
// $classLoader->unregister();
if (false === getenv('SYMFONY_PHPUNIT_REMOVE')) {
putenv('SYMFONY_PHPUNIT_REMOVE=');
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c855f16e7c222c9670fefee9294ed53b",
"content-hash": "f5e84160f51c5deffe5883d20a52bbb9",
"packages": [
{
"name": "api-platform/api-pack",
......@@ -10975,16 +10975,16 @@
},
{
"name": "symfony/browser-kit",
"version": "v4.2.2",
"version": "v4.2.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/browser-kit.git",
"reference": "313512c878805971aebddb5d1707bcf3f4e25df7"
"reference": "61d85c5af2fc058014c7c89504c3944e73a086f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/313512c878805971aebddb5d1707bcf3f4e25df7",
"reference": "313512c878805971aebddb5d1707bcf3f4e25df7",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/61d85c5af2fc058014c7c89504c3944e73a086f0",
"reference": "61d85c5af2fc058014c7c89504c3944e73a086f0",
"shasum": ""
},
"require": {
......@@ -11028,20 +11028,20 @@
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com",
"time": "2019-01-03T09:07:35+00:00"
"time": "2019-02-23T15:17:42+00:00"
},
{
"name": "symfony/css-selector",
"version": "v4.2.2",
"version": "v4.2.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "76dac1dbe2830213e95892c7c2ec1edd74113ea4"
"reference": "48eddf66950fa57996e1be4a55916d65c10c604a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/76dac1dbe2830213e95892c7c2ec1edd74113ea4",
"reference": "76dac1dbe2830213e95892c7c2ec1edd74113ea4",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/48eddf66950fa57996e1be4a55916d65c10c604a",
"reference": "48eddf66950fa57996e1be4a55916d65c10c604a",
"shasum": ""
},
"require": {
......@@ -11081,7 +11081,7 @@
],
"description": "Symfony CssSelector Component",
"homepage": "https://symfony.com",
"time": "2019-01-03T09:07:35+00:00"
"time": "2019-01-16T20:31:39+00:00"
},
{
"name": "symfony/debug-bundle",
......@@ -11430,16 +11430,16 @@
},
{
"name": "symfony/phpunit-bridge",
"version": "v4.2.2",
"version": "v4.2.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/phpunit-bridge.git",
"reference": "4d53b78ee50da242dffa4eb91ea1f0ee084945c5"
"reference": "2cc651a38fcb831a405c14fcb76fcb00320e7ee8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/4d53b78ee50da242dffa4eb91ea1f0ee084945c5",
"reference": "4d53b78ee50da242dffa4eb91ea1f0ee084945c5",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/2cc651a38fcb831a405c14fcb76fcb00320e7ee8",
"reference": "2cc651a38fcb831a405c14fcb76fcb00320e7ee8",
"shasum": ""
},
"require": {
......@@ -11449,7 +11449,6 @@
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
},
"suggest": {
"ext-zip": "Zip support is required when using bin/simple-phpunit",
"symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"
},
"bin": [
......@@ -11492,7 +11491,7 @@
],
"description": "Symfony PHPUnit Bridge",
"homepage": "https://symfony.com",
"time": "2019-01-03T09:07:35+00:00"
"time": "2019-02-18T06:49:49+00:00"
},
{
"name": "symfony/polyfill-php72",
......
......@@ -34,22 +34,22 @@ security:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# -> custom firewall for the admin area of the URL
admin:
pattern: /admin(.*)
form_login:
provider: fos_userbundle
login_path: /admin/login
check_path: /admin/login_check
use_forward: false
failure_path: null
success_handler: redirect.after.login
logout:
path: /admin/logout
target: /admin/login
anonymous: true
switch_user:
provider: fos_userbundle
context: mlc_context
# admin:
# pattern: /admin(.*)
# form_login:
# provider: fos_userbundle
# login_path: fos_user_security_login
# check_path: /admin/login_check
# use_forward: false
# failure_path: null
# success_handler: redirect.after.login
# logout:
# path: /admin/logout
# target: /admin/login
# anonymous: true
# switch_user:
# provider: fos_userbundle
# context: mlc_context
# access_denied_handler: App\Security\AccessDeniedHandler
# -> end custom configuration
main:
......@@ -99,10 +99,10 @@ security:
# Note: Only the *first* access control that matches will be used
access_control:
# Admin login page needs to be accessed without credential
- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/admin/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
......
security:
firewalls:
# replace 'main' by the name of your own firewall
main:
http_basic: ~
provider: fos_userbundle
\ No newline at end of file
......@@ -97,6 +97,12 @@ services:
tags:
- { name: doctrine.event_listener, event: preUpdate }
mlc.user.listener:
class: App\EventListener\UserListener
autowire: true
tags:
- { name: kernel.event_subscriber }
###### Configuration de l'admin ######
admin.adherent.gerer:
......
......@@ -89,7 +89,7 @@ class PrestataireAdmin extends AbstractAdmin
if (!$childAdmin && !in_array($action, ['edit', 'show'])) {
return;
}
$user = $this->security->getUser();
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
$user = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(User::class)->findOneBy(array('prestataire' => $id));
......@@ -108,6 +108,7 @@ class PrestataireAdmin extends AbstractAdmin
{
// Initialize prestataire
$presta = $this->getSubject();
$user = $this->security->getUser();
$now = new \DateTime();
$cotisation = null;
if ($this->isCurrentRoute('create')) {
......@@ -410,6 +411,7 @@ class PrestataireAdmin extends AbstractAdmin
protected function configureListFields(ListMapper $listMapper): void
{
unset($this->listModes['mosaic']);
$user = $this->security->getUser();
$listMapper
->addIdentifier('user.username')
->addIdentifier('user.email')
......
......@@ -14,6 +14,11 @@ use App\Form\Type\AdhererFormType;
use App\Form\Type\ContactFormType;
use App\Form\Type\TransactionAdherentPrestataireFormType;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Form\Factory\FactoryInterface;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Geocoder\Provider\Nominatim\Nominatim;
use Geocoder\Query\GeocodeQuery;
......@@ -21,22 +26,28 @@ use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Swagger\Annotations as SWG;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Security as Secur;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
class IndexController extends AbstractController
{
private $eventDispatcher;
private $em;
private $um;
private $userManager;
private $tokenManager;
public function __construct(EntityManagerInterface $em, UserManagerInterface $um, CsrfTokenManagerInterface $tokenManager = null)
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $em, UserManagerInterface $userManager, CsrfTokenManagerInterface $tokenManager = null)
{
$this->eventDispatcher = $eventDispatcher;
$this->em = $em;
$this->um = $um;
$this->userManager = $userManager;
$this->tokenManager = $tokenManager;
}
......@@ -80,7 +91,7 @@ class IndexController extends AbstractController
// @TODO : formulaire d'adhésion sans cotisation ? à valider après ?
$adherent = new Adherent();
$user = $this->um->createUser();
$user = $this->userManager->createUser();
$groupe = $this->em->getRepository(Usergroup::class)->findOneByName('Adherent');
$user->setEnabled(true);
$user->addGroup($groupe);
......
......@@ -208,7 +208,7 @@ class Groupeprestataire
public function __toString(): string
{
$return = $this->getName();
$return = $this->getName() ? $this->getName() : 'GroupePrestataire';
if ($this->type != null) {
$return .= ' ('.strtoupper($this->type).')';
}
......
<?php
namespace App\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\UserEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
/**
* Listener responsible to change the redirection at the end of the password resetting
*/
class UserListener implements EventSubscriberInterface
{
protected $em;
protected $router;
protected $session;
protected $tokenGenerator;
public function __construct(EntityManagerInterface $em, RouterInterface $router, SessionInterface $session, TokenGeneratorInterface $tokenGenerator)
{
$this->em = $em;
$this->router = $router;
$this->session = $session;
$this->tokenGenerator = $tokenGenerator;
}
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::CHANGE_PASSWORD_SUCCESS => 'onChangePasswordSuccess',
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
FOSUserEvents::REGISTRATION_FAILURE => 'onRegistrationFailure',
FOSUserEvents::RESETTING_RESET_SUCCESS => 'onResetSuccess',
FOSUserEvents::USER_CREATED => 'onUserCreated',
);
}
public function onChangePasswordSuccess(FormEvent $event)
{
$url = $this->router->generate('index');
$event->setResponse(new RedirectResponse($url));
}
public function onRegistrationSuccess(FormEvent $event)
{
$url = $this->router->generate('index');
$event->setResponse(new RedirectResponse($url));
}
public function onRegistrationFailure(FormEvent $event)
{
$url = $this->router->generate('index');
$event->setResponse(new RedirectResponse($url));
}
public function onResetSuccess(FormEvent $event)
{
$url = $this->router->generate('index');
$event->setResponse(new RedirectResponse($url));
}
public function onUserCreated(UserEvent $event)
{
// @TODO : notification ?
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class HiddenEntityExtension extends AbstractTypeExtension
{
public function getExtendedTypes()
public static function getExtendedTypes()
{
return array(HiddenType::class);
}
......
{% set userlogintitle = 'Modifier votre mot de passe !'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
......
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "@FOSUser/Group/edit_content.html.twig" %}
{% endblock fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
{{ form_start(form, { 'action': path('fos_user_group_edit', {'groupName': group_name}), 'attr': { 'class': 'fos_user_group_edit' } }) }}
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'group.edit.submit'|trans }}" />
</div>
{{ form_end(form) }}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "@FOSUser/Group/list_content.html.twig" %}
{% endblock fos_user_content %}
<div class="fos_user_group_list">
<ul>
{% for group in groups %}
<li><a href="{{ path('fos_user_group_show', {'groupName': group.getName()} ) }}">{{ group.getName() }}</a></li>
{% endfor %}
</ul>
</div>
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "@FOSUser/Group/new_content.html.twig" %}
{% endblock fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
{{ form_start(form, { 'action': path('fos_user_group_new'), 'attr': { 'class': 'fos_user_group_new' } }) }}
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'group.new.submit'|trans }}" />
</div>
{{ form_end(form) }}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "@FOSUser/Group/show_content.html.twig" %}
{% endblock fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
<div class="fos_user_group_show">
<p>{{ 'group.show.name'|trans }}: {{ group.getName() }}</p>
</div>
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "@FOSUser/Profile/edit_content.html.twig" %}
{% endblock fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
{{ form_start(form, { 'action': path('fos_user_profile_edit'), 'attr': { 'class': 'fos_user_profile_edit' } }) }}
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'profile.edit.submit'|trans }}" />
</div>
{{ form_end(form) }}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
{% include "@FOSUser/Profile/show_content.html.twig" %}
{% endblock fos_user_content %}
{% trans_default_domain 'FOSUserBundle' %}
<div class="fos_user_user_show">
<p>{{ 'profile.show.username'|trans }}: {{ user.username }}</p>
<p>{{ 'profile.show.email'|trans }}: {{ user.email }}</p>
</div>
{% set userlogintitle = 'Vérifiez vos courriels !'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% trans_default_domain 'FOSUserBundle' %}
......
{% set userlogintitle = 'Inscriptioj confirmée !'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% trans_default_domain 'FOSUserBundle' %}
......
{% set userlogintitle = 'INSCRIPTION'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
......
{% set userlogintitle = 'Mot de passe réinitialisé !'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% trans_default_domain 'FOSUserBundle' %}
......
{% set userlogintitle = 'Réinitialiser le mot de passe'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
......
{% set userlogintitle = 'Réinitialiser le mot de passe'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% block fos_user_content %}
......
{# MLC : Overwrite fos user template for login #}
{% extends 'common/layout.html.twig' %}
{% set userlogintitle = 'Se connecter'|trans %}
{% extends "@FOSUser/layout.html.twig" %}
{% block content %}
<div class='container homepage'>
<div class='row'>
<div class='col-0 col-md-1'>
</div>
<div class='col-12 col-md-10 text-center'>
<div class="card my-4 mx-4">
<div class="card-header">{{'Se connecter'|trans}}</div>
<div class="card-body">
<div class="card-text mx-auto">
{% block fos_user_content %}
{% include 'common/login.html.twig' %}
</div>
</div>
</div>
</div>
<div class='col-0 col-md-1'>
</div>
</div>
</div>
{% endblock %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<div>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
{{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} |
<a href="{{ path('fos_user_security_logout') }}">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
</a>
{% else %}
<a href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|trans({}, 'FOSUserBundle') }}</a>
{% endif %}
</div>
{% if app.request.hasPreviousSession %}
{% for type, messages in app.session.flashbag.all() %}
{% for message in messages %}
<div class="flash-{{ type }}">
{{ message }}
</div>
{% endfor %}
{% endfor %}
{% endif %}
{# MLC : Overwrite fos user template for login #}
{% extends 'common/layout.html.twig' %}
<div>
{% set userlogintitle = userlogintitle is defined ? userlogintitle : 'CONNEXION'|trans %}
{% block content %}
<div class='container login'>
<div class='row'>
<div class='col-0 col-md-1'>
</div>
<div class='col-12 col-md-10 text-center'>
<div class="card my-4 mx-4">
<div class="card-header">{{ userlogintitle }}</div>
<div class="card-body">
<div class="card-text mx-auto">
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
</body>
</html>
</div>
</div>
</div>
<div class='col-0 col-md-1'>
</div>
</div>
</div>
{% endblock %}
......@@ -25,6 +25,7 @@
</div>
<div class='row'>
<div class='col-12 text-center'>
<a href="{{ path("fos_user_resetting_request") }}" class='mr-2'>Mot de passe oublié ?</a>
<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label class='ml-2' for="remember_me">{{ 'security.login.remember_me'|trans }}</label>
</div>
......
......@@ -24,7 +24,7 @@
{% include 'common/login.html.twig' %}
{% endset %}
{% include 'block/modal.html.twig' %}
<a class='btn btn-secondary w-100 mb-4' data-toggle="modal" data-target="#{{ modal_id }}" title='{{'Se connecter'|trans}}' href="{{path('fos_user_security_login')}}">{{'Se connecter'|trans}}</a>
<a class='btn btn-primary w-100 mb-4' data-toggle="modal" data-target="#{{ modal_id }}" title='{{'Se connecter'|trans}}' href="{{path('fos_user_security_login')}}">{{'Se connecter'|trans}}</a>
{% endif %}
{% include 'common/news.html.twig' %}
{% endblock colonne_droite %}
......
<?php
namespace App\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ApplicationAvailabilityFunctionalTest extends WebTestCase
{
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful($url)
{
$client = static::createClient([]);
$client->request('GET', $url);
$this->assertTrue($client->getResponse()->isSuccessful());
}
public function urlProvider()
{
yield ['/'];
yield ['/adherer'];
yield ['/news'];
yield ['/faq'];
yield ['/contact'];
yield ['/login'];
yield ['/prestataires/liste'];
yield ['/prestataires/carte'];
yield ['/prestataires/rubriques'];
yield ['/partenaires/liste'];
yield ['/comptoirs/liste'];
yield ['/comptoirs/carte'];
yield ['/groupe/prestataires/amap/carte'];
yield ['/groupe/prestataires/marche/carte'];
yield ['/resetting/request'];
}
/**
* @dataProvider adminUrlProvider
*/
public function testADMINPageIsSuccessful($url)
{
$client = static::createClient([], [
'PHP_AUTH_USER' => 'adminuser',
'PHP_AUTH_PW' => 'test',
]);
$client->request('GET', $url);
$this->assertTrue($client->getResponse()->isSuccessful());
}
public function adminUrlProvider()
{
yield ['/'];
yield ['/admin/dashboard'];
yield ['/admin/app/user/list'];
yield ['/admin/app/user/create'];
yield ['/admin/app/usergroup/list'];
yield ['/admin/adherent/list'];
yield ['/admin/adherent/create'];
yield ['/admin/cotisation_adherent/list'];
yield ['/admin/prestataire/list'];
yield ['/admin/prestataire/create'];
yield ['/admin/cotisation_prestataire/list'];
yield ['/admin/cotisation_prestataire/create'];
yield ['/admin/app/groupeprestataire/list'];
yield ['/admin/app/groupeprestataire/create'];
yield ['/admin/app/groupe/list'];
yield ['/admin/app/groupe/create'];
yield ['/admin/app/comptoir/list'];
yield ['/admin/app/comptoir/create'];
yield ['/admin/app/news/list'];
yield ['/admin/app/news/create'];
yield ['/admin/app/document/list'];
yield ['/admin/app/document/create'];
yield ['/admin/app/page/list'];
yield ['/admin/app/page/create'];
yield ['/admin/app/rubrique/list'];
yield ['/admin/app/rubrique/create'];
yield ['/admin/app/faq/list'];
yield ['/admin/app/faq/create'];
yield ['/admin/translations/list'];
yield ['/admin/app/flux/list'];
yield ['/admin/cotisation/list'];
yield ['/admin/cotisation/create'];
yield ['/admin/app/transfert/list'];
yield ['/admin/app/transaction/list'];
yield ['/admin/app/transfertprestatairesiege/list'];
yield ['/admin/sonata/menu/list'];
yield ['/admin/sonata/menu/create'];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment