mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
login form
This commit is contained in:
parent
0aba2f571d
commit
cbbf2e0524
50
Controller/LoginController.php
Normal file
50
Controller/LoginController.php
Normal 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -26,3 +26,9 @@ chill_main_admin_central:
|
||||
login:
|
||||
path: /login
|
||||
defaults: { _controller: ChillMainBundle:Login:login }
|
||||
|
||||
login_check:
|
||||
path: /login_check
|
||||
|
||||
logout:
|
||||
path: /logout
|
||||
|
19
Resources/views/Login/login.html.twig
Normal file
19
Resources/views/Login/login.html.twig
Normal 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 %}
|
16
Tests/Controller/LoginControllerTest.php
Normal file
16
Tests/Controller/LoginControllerTest.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user