Skip to content

Instantly share code, notes, and snippets.

@Shapit0
Last active December 30, 2015 08:49
Show Gist options
  • Save Shapit0/7805557 to your computer and use it in GitHub Desktop.
Save Shapit0/7805557 to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../src/app/UserProvider.php';
use Silex\Provider\FormServiceProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\User;
$app = new Silex\Application();
$app['debug'] = true;
$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());
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
***
));
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'login' => array(
'pattern' => '^/login$',
'anonymous' => true,
),
'secured' => array(
'pattern' => '^/.*$',
'form' => array('login_path' => '/login', 'check_path' => '/admin/login_check'),
'logout' => array('logout_path' => '/logout'),
'users' => $app->share(function () use ($app) {
return new UserProvider($app['db']);
}),
),
),
)
);
$app['security.access_rules'] = array(
array('^/.*$', 'ROLE_ADMIN'),
);
////////////////////////////////////////////////////////////////////////////////////// INDEX
$app->get('/', function (request $request) use ($app) {
return $app['twig']->render('index.twig', array(
'error' => $app['security.last_error']($request),
'last_username' => $app['session']->get('_security.last_username'),
));
})
->bind('index');
////////////////////////////////////////////////////////////////////////////////////// INDEX
$app->get('/login', function (request $request) use ($app) {
return $app['twig']->render('index.twig', array(
'error' => $app['security.last_error']($request),
'last_username' => $app['session']->get('_security.last_username'),
));
})
->bind('login');
////////////////////////////////////////////////////////////////////////////////////// LOGIN/Check_path
$app->post('/admin/login_check', function(Request $request) use ($app) {
echo "foooooooooo";
return $app['twig']->render('login_check.twig');
})
->bind('login_check');
<form action="{{ path('admin_login_check') }}" method="post">
{{ error }}
<input type="text" name="_username" value="{{ last_username }}" />
<input type="password" name="_password" value="" />
<input type="submit" name="submit" class="btn btn-warning" style="margin-top:30px;" value="Войти">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment