Finished authentication
Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>master
parent
f2370faa68
commit
e1fde17057
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\SecurityBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Security\Core\SecurityContext;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
public function loginAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$session = $request->getSession();
|
||||
|
||||
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
|
||||
{
|
||||
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
|
||||
}
|
||||
|
||||
return $this->render('KekRozsakSecurityBundle:Default:login.html.twig', array(
|
||||
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
|
||||
'error' => $error,
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\SecurityBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This is the class that validates and merges configuration from your app/config files
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('kek_rozsak_security');
|
||||
|
||||
// Here you should define the parameters that are allowed to
|
||||
// configure your bundle. See the documentation linked above for
|
||||
// more information on that topic.
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\SecurityBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
|
||||
*/
|
||||
class KekRozsakSecurityExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\SecurityBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class KekRozsakSecurityBundle extends Bundle
|
||||
{
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
KekRozsakSecurityBundle_login:
|
||||
pattern: /login
|
||||
defaults:
|
||||
_controller: KekRozsakSecurityBundle:Default:login
|
||||
|
||||
KekRozsakSecurityBundle_login_check:
|
||||
pattern: /login_check
|
||||
|
||||
KekRozsakSecurityBundle_logout:
|
||||
pattern: /logout
|
@ -0,0 +1,6 @@
|
||||
parameters:
|
||||
# kek_rozsak_security.example.class: KekRozsak\SecurityBundle\Example
|
||||
|
||||
services:
|
||||
kek_rozsak_security.encoder.crypt:
|
||||
class: KekRozsak\SecurityBundle\Service\CryptEncoder
|
@ -0,0 +1,13 @@
|
||||
{% extends '::main_template.html.twig' %}
|
||||
{% block title %}- Bejelentkezés{% endblock %}
|
||||
{% block content %}
|
||||
{% if error %}
|
||||
<div id="error-message">{{ error.message }}</div>
|
||||
{% endif %}
|
||||
|
||||
<form action="{{ path('KekRozsakSecurityBundle_login_check') }}" method="post">
|
||||
<input type="text" id="username" name="_username" value="{{ last_username }}" />
|
||||
<input type="password" id="password" name="_password" />
|
||||
<button type="submit">Bejelentkezés</button>
|
||||
</form>
|
||||
{% endblock content %}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace KekRozsak\SecurityBundle\Service;
|
||||
|
||||
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
||||
|
||||
class CryptEncoder implements PasswordEncoderInterface
|
||||
{
|
||||
function encodePassword($raw, $salt)
|
||||
{
|
||||
return crypt($raw);
|
||||
}
|
||||
|
||||
function isPasswordValid($encoded, $raw, $salt)
|
||||
{
|
||||
return (crypt($raw, $salt) == $encoded);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\SecurityBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DefaultControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
|
||||
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue