2016-01-12 19:57:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Mmi\Bundle\EnigmaBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
2016-01-12 20:31:48 +01:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
2016-01-12 23:51:17 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
2016-01-12 19:57:14 +01:00
|
|
|
|
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2016-01-12 23:51:17 +01:00
|
|
|
* @Route("/enigma/?", name="enigma")
|
2016-01-12 20:31:48 +01:00
|
|
|
* @Template()
|
2016-01-12 19:57:14 +01:00
|
|
|
*/
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2016-01-12 23:51:17 +01:00
|
|
|
if (!$this->get('session')->get('user')) {
|
|
|
|
return $this->redirectToRoute('enigma_login');
|
|
|
|
}
|
|
|
|
|
2016-01-12 20:31:48 +01:00
|
|
|
return [];
|
2016-01-12 19:57:14 +01:00
|
|
|
}
|
2016-01-12 23:51:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/enigma/login", name="enigma_login")
|
|
|
|
* @Template()
|
|
|
|
*/
|
|
|
|
public function loginAction(Request $request)
|
|
|
|
{
|
|
|
|
if ($this->get('session')->get('user')) {
|
|
|
|
return $this->redirectToRoute('enigma');
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = $this->createFormBuilder()
|
|
|
|
->add('username', TextType::class, ['required' => true])
|
|
|
|
->add('password', PasswordType::class, ['required' => true])
|
|
|
|
->add('Se connecter', SubmitType::class)
|
|
|
|
->getForm();
|
|
|
|
|
|
|
|
if ($request->isMethod('post')) {
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
if ($form->isValid()) {
|
|
|
|
$user = $this->getDoctrine()
|
|
|
|
->getRepository('MmiEnigmaBundle:Team')
|
|
|
|
->findOneBy([
|
|
|
|
'username' => $form->getData()['username'],
|
|
|
|
'password' => $form->getData()['password'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($user === null) {
|
|
|
|
$invalid = true;
|
|
|
|
} else {
|
|
|
|
$this->get('session')->set('user', $user);
|
|
|
|
|
|
|
|
return $this->redirectToRoute('enigma');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'form' => $form->createView(),
|
|
|
|
'invalid' => !empty($invalid),
|
|
|
|
];
|
|
|
|
}
|
2016-01-12 19:57:14 +01:00
|
|
|
}
|