<?php
namespace App\Controller;
use App\ClassTheatre\TheatreController;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheatreCore\Entity\Extranetusers;
class MontheatreConnexionController extends TheatreController
{
// page de connexion
public $page_connexion = '/montheatre/connexion';
// page de recup des codes
public $page_recuppass = '/montheatre/recuppass';
// page de validation
public $validation_page = '/montheatre/validation/';
// page de profil
public $login_page = '/montheatre/';
public $params = array();
protected $authenticationUtils;
// {{{ _construct()
/** constructeur hérité
*
*/
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, TokenStorageInterface $tokenStorage, AuthenticationUtils $authenticationUtils)
{
parent::__construct($translator, $tokenStorage);
$this->context['controller'] = $this->view->controller = 'montheatre';
$this->page_recuppass = $_ENV['URL_THNET'] . $this->page_recuppass;
$this->em = $em;
$this->authenticationUtils = $authenticationUtils;
}
// }}}
// {{{ view()
/** Affichage
*
* @Route("/montheatre/connexion", name="app_login")
*
* @access public
*/
public function action_connexion(Request $request, $execute = true, $params = [])
{
//Si l'utilisateur est déjà connecté on le redirige
if ($this->getUser() instanceof Extranetusers) {
if (empty($params['ignore_redirect'])) {
return $this->redirect('/montheatre/');
}
return true;
}
// get the login error if there is one
$error = $request->getSession()->getFlashBag()->get('error');
$request->getSession()->getFlashBag()->clear();
// last username entered by the user
$lastUsername = $this->authenticationUtils->getLastUsername();
$entete_connexion = $this->getEnteteConnexion('entete_connexion');
if (!empty($entete_connexion)) {
$this->context['view']->entete_connexion = $entete_connexion;
}
if (!empty($_REQUEST['special'])) {
$special = urldecode($_REQUEST['special']);
$this->context['view']->{'special_' . $special} = true;
}
$soustitre_connexion = $this->getEnteteConnexion('soustitre_connexion');
if (!empty($soustitre_connexion)) {
$this->context['view']->soustitre_connexion = $soustitre_connexion;
}
// si il y a un urifrom on l'ajoute en champ hidden
if (!empty($_REQUEST['urifrom'])) {
$urifrom = urldecode($_REQUEST['urifrom']);
$this->context['view']->urifrom = $urifrom;
} elseif (!empty($this->params['urifrom'])) {
$urifrom = $this->params['urifrom'];
$this->context['view']->urifrom = $urifrom;
} else {
$urifrom = '';
}
$this->context['view']->page_recuppass = $this->page_recuppass;
$this->context['view']->page_connexion = $this->page_connexion;
$this->context['view']->last_username = $lastUsername;
$this->context['view']->error = $error;
if ($execute) {
return $this->view('montheatre/connexion.html.twig');
}
return null;
}
// }}}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}
function getEnteteConnexion($nom)
{
if (isset($_REQUEST[$nom]) && !empty($_REQUEST[$nom])) {
$$nom = str_replace('_', '/', $_REQUEST[$nom]);
if (file_exists($_ENV['PATH_APP'] . $GLOBALS['module'] . '/views/' . $$nom . '/' . $nom . '.inc.html')) {
return $$nom;
}
}
}
}