login form

This commit is contained in:
Julien Fastré 2014-11-06 16:37:30 +01:00
parent 0aba2f571d
commit cbbf2e0524
4 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,50 @@
<?php
namespace Chill\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\SecurityContextInterface;
class LoginController extends Controller
{
/**
*
* @todo Improve this with http://symfony.com/blog/new-in-symfony-2-6-security-component-improvements#added-a-security-error-helper
* @param Request $request
* @return Response
*/
public function loginAction(Request $request)
{
$session = $request->getSession();
if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(
SecurityContextInterface::AUTHENTICATION_ERROR
);
} elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR);
$session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
} else {
$error = '';
}
$lastUsername = (null === $session) ?
'' : $session->get(SecurityContextInterface::LAST_USERNAME);
return $this->render('ChillMainBundle:Login:login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error
));
}
public function LoginCheckAction(Request $request)
{
}
}

View File

@ -26,3 +26,9 @@ chill_main_admin_central:
login:
path: /login
defaults: { _controller: ChillMainBundle:Login:login }
login_check:
path: /login_check
logout:
path: /logout

View File

@ -0,0 +1,19 @@
{% extends "::base.html.twig" %}
{% block title %}ChillMainBundle:Login:login{% endblock %}
{% block body %}
<h1>Welcome to the Login:login page</h1>
<p>{{ error }}</p>
<form method="POST" action="{{ path('login_check') }}">
<input type="text" name="_username" value="{{ last_username }}" />
<input type="password" name="_password" />
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}" />
<button type="submit">{{ 'Login'|trans }}</button>
</form>
{% endblock %}

View File

@ -0,0 +1,16 @@
<?php
namespace Chill\MainBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LoginControllerTest extends WebTestCase
{
public function testLogin()
{
$client = static::createClient();
$crawler = $client->request('GET', '/login');
}
}