Commit 510da366 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Fusion ConfirmationMail

parents ac15b8eb 592d7a5e
Loading
Loading
Loading
Loading
Loading
+110 −4
Changes for module/Application/config/others/admin.config.php: 110 added lines, 4 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Controller\Factory\RoleControllerFactory;
use Application\Controller\AdminController;
use Application\Controller\Factory\RoleControllerFactory;
use Application\Controller\MailConfirmationController;
use Application\Provider\Privilege\UtilisateurPrivileges;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Privilege\Privileges;
use Zend\Mvc\Router\Http\Literal;
use Zend\Mvc\Router\Http\Segment;
use UnicaenAuth\Provider\Privilege\Privileges;
use Application\Form\Factory\MailConfirmationFormFactory;
use Application\Form\Factory\MailConfirmationHydratorFactory;
use Application\Service\MailConfirmationServiceFactory;
use Application\Controller\Factory\MailConfirmationControllerFactory;
use Application\Provider\Privilege\ThesePrivileges;

return [
    'bjyauthorize'    => [
        'guards' => [
@@ -44,6 +51,25 @@ return [
                    ],
                    'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE,
                ],
                [
                    'controller' => MailConfirmationController::class,
                    'action'     => [
                        'index',
                        'envoie',
                        'reception',
                        'swap',
                        'remove'
                    ],
                    'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE,
                ],
                [
                    'controller' => MailConfirmationController::class,
                    'action'     => [
                        'envoie',
                        'reception',
                    ],
                    'privileges' => ThesePrivileges::THESE_CONSULTATION_FICHE,
                ],
            ],
        ],
    ],
@@ -71,6 +97,57 @@ return [
                    ],
                ],
            ],
            'mail-confirmation-acceuil' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/mail-confirmation-acceuil[/:id]',
                    'defaults' =>[
                        'controller' => MailConfirmationController::class,
                        'action' => 'index',
                    ],
                ],
            ],
            'mail-confirmation-swap' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/mail-confirmation-swap/:id',
                    'defaults' =>[
                        'controller' => MailConfirmationController::class,
                        'action' => 'swap',
                    ],
                ],
            ],
            'mail-confirmation-remove' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/mail-confirmation-remove/:id',
                    'defaults' =>[
                        'controller' => MailConfirmationController::class,
                        'action' => 'remove',
                    ],
                ],
            ],

            'mail-confirmation-envoie' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/mail-confirmation-envoie/:id',
                    'defaults' =>[
                        'controller' => MailConfirmationController::class,
                        'action' => 'envoie',
                    ],
                ],
            ],
            'mail-confirmation-reception' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/mail-confirmation-reception/:id/:code',
                    'defaults' =>[
                        'controller' => MailConfirmationController::class,
                        'action' => 'reception',
                    ],
                ],
            ],
            'modifier-privilege' => [
                'type'          => Segment::class,
                'options'       => [
@@ -82,6 +159,16 @@ return [
                    ],
                ],
            ],
            'cobaye' => [
                'type'          => Literal::class,
                'options'       => [
                    'route'         => '/cobaye',
                    'defaults'      => [
                        'controller'    => CobayeController::class,
                        'action'        => 'index',
                    ],
                ],
            ],
            'test-envoi-mail' => [
                'type'          => 'Segment',
                'options'       => [
@@ -122,18 +209,37 @@ return [
            ],
        ],
    ],

    'service_manager' => [
        'invokables' => array(
        ),
        'invokables' => [],
        'factories' => [
            'MailConfirmationService' => MailConfirmationServiceFactory::class,
        ],
    ],
    'controllers'     => [
        'invokables' => [
            'Application\Controller\Admin' => AdminController::class,

        ],
        'factories' => [
            'Application\Controller\Role' => RoleControllerFactory::class,
            MailConfirmationController::class => MailConfirmationControllerFactory::class,
            CobayeController::class => CobayeControllerFactory::class,

        ],
    ],

    'form_elements'   => [
        'invokables' => [
        ],
        'factories' => [
            'MailConfirmationForm' => MailConfirmationFormFactory::class,
        ],
    ],
    'hydrators' => [
        'factories' => [
            'MailConfirmationHydrator' => MailConfirmationHydratorFactory::class,
        ]
    ],

];
+2 −5
Changes for module/Application/config/others/doctorant.config.php: 2 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -53,13 +53,10 @@ return [
                    'modifier-persopass' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/modifier-persopass[/:detournement]',
                            'constraints' => [
                                'detournement' => '\d',
                            ],
                            'route'       => '/modifier-persopass[/:back]',
                            'defaults'    => [
                                'action' => 'modifier-persopass',
                                'detournement' => 0
                                'back' => 0
                            ],
                        ],
                    ],
+55 −35
Changes for module/Application/src/Application/Controller/DoctorantController.php: 55 added lines, 35 removed lines.
Original line number Diff line number Diff line
@@ -3,10 +3,12 @@
namespace Application\Controller;

use Application\Entity\Db\Doctorant;
use Application\Entity\Db\MailConfirmation;
use Application\Entity\Db\Variable;
use Application\Filter\DbExceptionFormatter;
use Application\RouteMatch;
use Application\Service\Doctorant\DoctorantServiceAwareTrait;
use Application\Service\MailConfirmationService;
use Application\Service\Variable\VariableServiceAwareTrait;
use Doctrine\DBAL\DBALException;
use UnicaenAuth\Authentication\Adapter\Ldap as LdapAuthAdapter;
@@ -20,58 +22,76 @@ class DoctorantController extends AbstractController
    use VariableServiceAwareTrait;
    use DoctorantServiceAwareTrait;

    /** @var MailConfirmationService $mailConfirmationService */
    private $mailConfirmationService;

    public function setMailConfirmationService(MailConfirmationService $mailConfirmationService)
    {
        $this->mailConfirmationService = $mailConfirmationService;
    }

    public function modifierPersopassAction()
    {
        $doctorant = $this->requestDoctorant();
        $form = $this->getModifierPersopassForm();
        $mailConfirmation = $this->mailConfirmationService->getDemandeConfirmeeByIndividu($doctorant->getIndividu());
        if ($mailConfirmation !== null) {
            $viewmodel = new ViewModel([
                'email' => $mailConfirmation->getEmail(),
            ]);
            $viewmodel->setTemplate('application/doctorant/demande-ok');
            return $viewmodel;
        }


        $mailConfirmation = $this->mailConfirmationService->getDemandeEnCoursByIndividu($doctorant->getIndividu());

        $form->setData([
            'identity' => $doctorant->getPersopass(),
            'credential' => '',
        //Si on a déjà une demande en attente
        $back = $this->params()->fromRoute('back');

//        var_dump($mailConfirmation->getIndividu()->__toString());
//        var_dump($mailConfirmation->getEmail());
//        var_dump($mailConfirmation->getCode());
//        var_dump($mailConfirmation->getEtat());
//        var_dump($back);
        if ($mailConfirmation !== null && ($back == 0 || $back === null)) {
            $viewmodel = new ViewModel([
                'email' => $mailConfirmation->getEmail(),
            ]);
            $viewmodel->setTemplate('application/doctorant/demande-encours');
            return $viewmodel;
        }

        if ($mailConfirmation === null) {
            $mailConfirmation = new MailConfirmation();
            $mailConfirmation->setIndividu($doctorant->getIndividu());
            $mailConfirmation->setEtat(MailConfirmation::ENVOYER);
        }
        $request = $this->getRequest();
        if ($request->isPost()) {
            /** @var ParametersInterface $post */
            $post = $this->getRequest()->getPost();
            $form->setData($post);
            if ($form->isValid()) {
                if ($result = $this->validatePersopass($post['identity'], $post['credential'])) {
                    try {
                        $this->doctorantService->updateDoctorant($doctorant, $result);

                        // prise en compte du paramètre GET 'return' positionné par SaisiePersopassRouteDeflector :
                        if ($redirectUri = $this->params()->fromQuery('return')) {
                            return $this->redirect()->toUrl($redirectUri);
                        }

                        if (!$request->isXmlHttpRequest()) {
                            return $this->redirect()->toRoute('home', [], [], true);
                        }
                    } catch (DBALException $e) {
                        $f = new DbExceptionFormatter();
                        $message = $f->filter($e);
                        $form->setMessages(['credential' => [$message]]);
                    }
                }
                else {
                    $form->setMessages(['credential' => ["Identifiant ou mot de passe incorrect"]]);
                }
            $data = $request->getPost();
            $email = $data['email'];
            if (filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
                $mailConfirmation->setEmail($email);
                $id = $this->mailConfirmationService->save($mailConfirmation);
                $this->mailConfirmationService->generateCode($id);
                return $this->redirect()->toRoute('mail-confirmation-envoie', ['id' => $id], [], true);
                var_dump("here");
            } else {
                $this->flashMessenger()->addErrorMessage("L'email fourni <strong>".$email."</strong> est non valide.");
            }
        }

        $form->setAttribute('action', $request->getRequestUri());
        $form = $this->getServiceLocator()->get('FormElementManager')->get('MailConfirmationForm');

        $variable = $this->variableService->getRepository()->findByCodeAndEtab(
            Variable::CODE_EMAIL_BDD,
            $doctorant->getEtablissement());
        $form->bind($mailConfirmation);

        return new ViewModel([
            'doctorant' => $doctorant,
            'form' => $form,
            'title' => "Saisie du Persopass",
            'detournement' => (bool) $this->params('detournement'),
            'emailBdD' => $variable->getValeur(),
            'title' => "Saisie du mail de contact",
            //'detournement' => (bool) $this->params('detournement'),
            //'emailBdD' => $variable->getValeur(),
        ]);
    }

+4 −0
Changes for module/Application/src/Application/Controller/Factory/DoctorantControllerFactory.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Application\Controller\DoctorantController;
use Application\Service\Doctorant\DoctorantService;
use Application\Service\Variable\VariableService;
use Zend\Mvc\Controller\ControllerManager;
use Application\Service\MailConfirmationService;

class DoctorantControllerFactory
{
@@ -20,13 +21,16 @@ class DoctorantControllerFactory
        /**
         * @var VariableService $variableService
         * @var DoctorantService $doctorantService
         * @var MailConfirmationService $mailConfirmationService
         */
        $variableService = $controllerManager->getServiceLocator()->get('VariableService');
        $doctorantService = $controllerManager->getServiceLocator()->get('DoctorantService');
        $mailConfirmationService = $controllerManager->getServiceLocator()->get('MailConfirmationService');

        $controller = new DoctorantController();
        $controller->setVariableService($variableService);
        $controller->setDoctorantService($doctorantService);
        $controller->setMailConfirmationService($mailConfirmationService);

        return $controller;
    }
+1 −1
Changes for module/Application/src/Application/Controller/Plugin/UrlDoctorant.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ class UrlDoctorant extends UrlPlugin
    public function modifierPersopassUrl(These $these)
    {
        return $this->fromRoute('doctorant/modifier-persopass',
            ['doctorant' => $these->getDoctorant()->getId()]
            ['doctorant' => $these->getDoctorant()->getId(), 'back' => 0],[], true
        );
    }
}
 No newline at end of file
Loading