Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?
  2.  
  3. require_once 'vendor/autoload.php';
  4.  
  5. $app = new SlimSlim(array(
  6. 'templates.path' => './template',
  7. 'debug' => true
  8. ));
  9.  
  10.  
  11. require("config/database.php");
  12. require_once("vendor/dabble/dabble/src/Dabble/Database.php");
  13. require_once("vendor/dabble/dabble/src/Dabble/Result.php");
  14.  
  15.  
  16.  
  17.  
  18. $db = new DabbleDatabase(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  19.  
  20. session_start();
  21.  
  22. date_default_timezone_set("Europe/Rome");
  23.  
  24. require 'app/GeCo.php';
  25.  
  26. $app->run();
  27.  
  28. ?>
  29.  
  30. <?php
  31.  
  32. require_once('classes/Login.php');
  33. use loginLogin;
  34.  
  35.  
  36. $app->get('/', function () use ($app) {
  37.  
  38. $app->redirect('/dashboard');
  39.  
  40. });
  41.  
  42. $app->get('/login', function () use ($app) {
  43.  
  44. $page = 'login.php';
  45. $app->render($page);
  46.  
  47. });
  48.  
  49. $app->get('/dashboard', function () use ($app) {
  50.  
  51. $page = 'dashboard.php';
  52. $app->render($page);
  53.  
  54. })->name('dash');;
  55.  
  56.  
  57. $app->post('/login', function () use ($app,$db) {
  58.  
  59. try {
  60.  
  61. $result=[];
  62. $username = $_POST['username'];
  63. $password = $_POST['password'];
  64.  
  65. $login = new Login($db);
  66. $result = $login->checkLogin($username,$password);
  67.  
  68. }catch (Exception $e) {
  69. error_log(json_encode(print_r($e->getTrace(), 1)));
  70. } finally {
  71.  
  72. if ($result) {
  73.  
  74. $_SESSION['loggedUser'] = $username;
  75. $_SESSION['password']=md5($password);
  76. $app->redirect('/dashboard');
  77. } else {
  78.  
  79. header ( 'Content-Type: application/json' );
  80. echo json_encode('Nessun utente trovato con questi dati.');
  81. exit();
  82.  
  83. }
  84.  
  85. }
  86.  
  87. });
  88.  
  89. RewriteEngine On
  90.  
  91. RewriteCond %{REQUEST_FILENAME} !-f
  92. RewriteRule ^ index.php [QSA,L]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement