Commit 2c40bc50 by Julien Jorry

Add notification by mail if an admin register a new user + fix view for creating new password

parent 1fe9362e
...@@ -16,6 +16,8 @@ namespace App\Application\Sonata\UserBundle\Admin; ...@@ -16,6 +16,8 @@ namespace App\Application\Sonata\UserBundle\Admin;
use App\Entity\Adherent; use App\Entity\Adherent;
use App\Entity\Geoloc; use App\Entity\Geoloc;
use App\Entity\Groupe; use App\Entity\Groupe;
use App\Events\MLCEvents;
use FOS\UserBundle\Event\UserEvent;
use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\FormMapper;
...@@ -337,6 +339,14 @@ class UserAdmin extends BaseUserAdmin ...@@ -337,6 +339,14 @@ class UserAdmin extends BaseUserAdmin
$this->postPersist($user); $this->postPersist($user);
} }
public function prePersist($user)
{
if ($user->isEnabled()) {
$this->getConfigurationPool()->getContainer()->get('event_dispatcher')->dispatch(MLCEvents::REGISTRATION_USER, new UserEvent($user, $this->getRequest()));
}
}
public function postPersist($user): void public function postPersist($user): void
{ {
// On empeche d'enregistrer des comptoirs/groupes gérés si la case correspondante n'est pas cochée dans le choix des possiblegroups // On empeche d'enregistrer des comptoirs/groupes gérés si la case correspondante n'est pas cochée dans le choix des possiblegroups
......
...@@ -55,6 +55,7 @@ class MLCEventListener implements EventSubscriberInterface ...@@ -55,6 +55,7 @@ class MLCEventListener implements EventSubscriberInterface
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return [ return [
MLCEvents::REGISTRATION_USER => 'onRegistrationUser',
MLCEvents::REGISTRATION_ADHERENT => 'onRegistrationAdherent', MLCEvents::REGISTRATION_ADHERENT => 'onRegistrationAdherent',
MLCEvents::REGISTRATION_PRESTATAIRE => 'onRegistrationPrestataire', MLCEvents::REGISTRATION_PRESTATAIRE => 'onRegistrationPrestataire',
MLCEvents::REGISTRATION_CAISSIER => 'onRegistrationCaissier', MLCEvents::REGISTRATION_CAISSIER => 'onRegistrationCaissier',
...@@ -80,6 +81,12 @@ class MLCEventListener implements EventSubscriberInterface ...@@ -80,6 +81,12 @@ class MLCEventListener implements EventSubscriberInterface
]; ];
} }
public function onRegistrationUser(UserEvent $event)
{
$user = $event->getUser();
$this->sendMailRegistration($user, ['type' => 'user']);
}
public function onRegistrationPrestataire(PrestataireEvent $event) public function onRegistrationPrestataire(PrestataireEvent $event)
{ {
$user = $event->getUser(); $user = $event->getUser();
...@@ -117,13 +124,13 @@ class MLCEventListener implements EventSubscriberInterface ...@@ -117,13 +124,13 @@ class MLCEventListener implements EventSubscriberInterface
$user->setPasswordRequestedAt(new \DateTime()); $user->setPasswordRequestedAt(new \DateTime());
$this->userManager->updateUser($user); $this->userManager->updateUser($user);
$subject = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NAME_SMALL) . ' : ' . $this->translator->trans('Création de votre compte adhérent'); $subject = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NAME_SMALL) . ' : ' . $this->translator->trans('Création de votre compte');
$mail = (new \Swift_Message($subject)) $mail = (new \Swift_Message($subject))
->setFrom($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NOTIF_EMAIL)) ->setFrom($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NOTIF_EMAIL))
->setTo($user->getEmail()) ->setTo($user->getEmail())
->setBody( ->setBody(
$this->templating->render( $this->templating->render(
'@kohinos/email/admin_add_' . ((isset($params['type']) && in_array($params['type'], ['adherent', 'prestataire', 'caissier'])) ? $params['type'] : 'adherent') . '.html.twig', '@kohinos/email/admin_add_' . ((isset($params['type']) && in_array($params['type'], ['adherent', 'prestataire', 'caissier', 'user'])) ? $params['type'] : 'adherent') . '.html.twig',
array_merge($params, [ array_merge($params, [
'subject' => $subject, 'subject' => $subject,
'user' => $user, 'user' => $user,
......
...@@ -12,6 +12,7 @@ namespace App\Events; ...@@ -12,6 +12,7 @@ namespace App\Events;
class MLCEvents class MLCEvents
{ {
/* GLOBAL EVENTS*/ /* GLOBAL EVENTS*/
const REGISTRATION_USER = 'mlc.registration_user';
const REGISTRATION_ADHERENT = 'mlc.registration_adherent'; const REGISTRATION_ADHERENT = 'mlc.registration_adherent';
const REGISTRATION_PRESTATAIRE = 'mlc.registration_prestataire'; const REGISTRATION_PRESTATAIRE = 'mlc.registration_prestataire';
const REGISTRATION_CAISSIER = 'mlc.registration_caissier'; const REGISTRATION_CAISSIER = 'mlc.registration_caissier';
......
{% set userlogintitle = 'Réinitialiser le mot de passe'|trans %} {% set user = form.vars.value %}
{% if user.lastLogin == null %}
{% set userlogintitle = 'Validation du compte et création de votre mot de passe'|trans %}
{% else %}
{% set userlogintitle = 'Réinitialiser le mot de passe'|trans %}
{% endif %}
{% extends "@kohinos/bundles/FOSUserBundle/layout.html.twig" %} {% extends "@kohinos/bundles/FOSUserBundle/layout.html.twig" %}
{% block fos_user_content %} {% block fos_user_content %}
......
...@@ -48,13 +48,21 @@ ...@@ -48,13 +48,21 @@
<span style="{# font-size: 1em; color: grey; #}"> <span style="{# font-size: 1em; color: grey; #}">
<i class="fas fa-user"></i> <i class="fas fa-user"></i>
<span class='ml-1'> <span class='ml-1'>
{% if app.session.has('_groupId') %} {% if app.session.has('_groupId') and app.session.get('_groupId').name != 'ROLE_USER' %}
{% set groupeUser = app.session.get('_groupId') %} {% set groupeUser = app.session.get('_groupId') %}
{{groupeUser.name}} {{groupeUser.name}}
{% elseif app.user.groups|length > 0 %} {% elseif app.user.groups|length > 0 %}
{{app.user.groups[0].name}} {% if app.user.groups[0].name != 'ROLE_USER' %}
{{app.user.groups[0].name}}
{% else %}
{{app.user.name}}
{% endif %}
{% elseif app.user.roles|length > 0 %} {% elseif app.user.roles|length > 0 %}
{{app.user.roles[0]}} {% if app.user.roles[0] != 'ROLE_USER' %}
{{app.user.roles[0]}}
{% else %}
{{app.user.name}}
{% endif %}
{% else %} {% else %}
{{app.user.name}} {{app.user.name}}
{% endif %} {% endif %}
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
{% endset %} {% endset %}
{% block content %} {% block content %}
<h2 style="font-size: 18px; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-weight: bold; line-height: 1.2em; margin: 40px 0 10px;">{{ 'Valider la création de votre compte'|trans }}</h2><br/> <h2 style="font-size: 18px; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-weight: bold; line-height: 1.2em; margin: 40px 0 10px;">{{ 'Valider la création de votre compte adhérent'|trans }}</h2><br/>
<p> <p>
{{ 'Un administreur a crée votre nouveau compte MLC'|trans }} {{ 'Un administreur a crée votre nouveau compte adhérent'|trans }}
{{ user.name|title }} {{ user.name|title }}
</p> </p>
<p> <p>
......
{% extends '@kohinos/email/email_layout.html.twig' %}
{% set title %}{% spaceless %}
{{ subject }}
{% endspaceless %}
{% endset %}
{% block content %}
<h2 style="font-size: 18px; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-weight: bold; line-height: 1.2em; margin: 40px 0 10px;">{{ 'Valider la création de votre compte'|trans }}</h2><br/>
<p>
{{ 'Un administreur a crée votre nouveau compte'|trans }}
{{ user.name|title }}
</p>
<p>
{{ 'Pour valider votre nouveau compte, cliquez sur ce lien : '|trans }}<br/>
<a href='{{confirmationUrl}}'>{{confirmationUrl}}</a>
</p>
{% endblock %}
\ No newline at end of file
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