Advertisement
Guest User

Untitled

a guest
Apr 21st, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. use SymfonyComponentDebugErrorHandler;
  2. use SymfonyComponentDebugExceptionHandler;
  3.  
  4. // Register global error and exception handlers
  5. ErrorHandler::register();
  6. ExceptionHandler::register();
  7.  
  8. // Register service providers
  9. $app->register(new SilexProviderDoctrineServiceProvider());
  10. $app->register(new SilexProviderTwigServiceProvider(), array(
  11. 'twig.path' => __DIR__ . '/../views',
  12. ));
  13. $app->register(new SilexProviderUrlGeneratorServiceProvider());
  14. $app->register(new SilexProviderSessionServiceProvider());
  15. $app->register(new SilexProviderSecurityServiceProvider(), array(
  16. 'security.firewalls' => array(
  17. 'secured' => array(
  18. 'pattern' => '^/',
  19. 'anonymous' => true,
  20. 'logout' => array('logout_path' => '/admin/logout', 'invalidate_session' => true),
  21. 'form' => array('login_path' => 'login', 'check_path' => '/login_check'),
  22. 'users' => $app->share(function () use ($app) {
  23. return new skiDAOMemberDAO($app['db']);
  24. }),
  25. ),
  26. ),
  27. ));
  28.  
  29. // register services
  30. $app['dao.member'] = $app->share(function ($app) {
  31. return new skiDAOMemberDAO($app['db']);
  32. });
  33.  
  34. use SymfonyComponentHttpFoundationRequest;
  35.  
  36. // Home page
  37. $app->get('/', function () use ($app) {
  38. return $app['twig']->render('index.html.twig');
  39. })->bind('home');
  40.  
  41. // TODO : never called
  42. $app->post('/ajax/login/', function (Request $request) use ($app) {
  43. // HERE : how to return if the login was performed well ?
  44. return $app['security.last_error']($request);
  45. })->bind('ajax_login');
  46.  
  47. $app->get('/login/', function (Request $request) use ($app) {
  48. return $app['twig']->render('login.html.twig', array(
  49. 'error' => $app['security.last_error']($request),
  50. 'last_username' => $app['session']->get('_security.last_username'),
  51. ));
  52. })->bind('login');
  53.  
  54. $app->get('/includes/header/', function () use ($app) {
  55. return $app['twig']->render('header.html.twig');
  56. })->bind('header');
  57.  
  58. // Connexion
  59. $(document).on('click', '#connexion_submit_button', function () {
  60. // Connexion Ajax
  61. var username = $('#connexion_pseudo').val();
  62. var password = $('#connexion_password').val();
  63.  
  64. $.ajax({
  65. type: 'POST',
  66. url: '/ski/web/login_check',
  67. data: '_username=' + username + '&_password=' + password,
  68. beforeSend: function () {
  69. $('#connexion_submit_button').html('Patientez...');
  70. },
  71. success: function (data) {
  72.  
  73. // TODO : generate custom animations if user is logged or not
  74. console.log(data);
  75. $('#connexion_submit_button').html('Connexion');
  76. }
  77. });
  78. return false;
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement