Skip to content

Instantly share code, notes, and snippets.

@fesor
Forked from Shapit0/app
Last active December 30, 2015 03:59
Show Gist options
  • Save fesor/7772687 to your computer and use it in GitHub Desktop.
Save fesor/7772687 to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
***
));
*/
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'locale_fallbacks' => array('en'),
));
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/views',
));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
use Silex\Provider\FormServiceProvider;
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
use Symfony\Component\HttpFoundation\Request;
$app->register(new Silex\Provider\SessionServiceProvider());
// Security
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'login' => array(
'pattern' => '^/$',
'anonymous' => array(),
),
'secured' => array(
'pattern' => '^/.*$',
'form' => array('login_path' => '/', 'check_path' => '/login_check'),
'users' => array(
'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
),
),
)
));
////////////////////////////////////////////////////////////////////////////////////// INDEX
$app->get('/', function (request $request) use ($app) {
$data = array();
$form = $app['form.factory']->createBuilder('form', $data)
->add('_username')
->add('_password', 'password')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
}
return $app['twig']->render('index.twig', array('form' => $form->createView()));
})
->bind('index');
////////////////////////////////////////////////////////////////////////////////////// INDEX-test
$app->post('/login', function(Request $request) use ($app) {
return $app['twig']->render('login.html', array(
'error' => $app['security.last_error']($request),
'last_username' => $app['session']->get('_security.last_username'),
));
})
->bind('login_path');
////////////////////////////////////////////////////////////////////////////////////// LOGIN/Check_path
$app->post('/login_check', function(Request $request) use ($app) {
if (isset($app['security.last_error'])) {
var_dump($app['security.last_error']);
var_dump($request);
}
return $app['twig']->render('login_check.twig');
})
->bind('login_check');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment