index.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. include_once('../../index.php');
  3. include_once('templates/core/Smarty.class.php');
  4. include_once('logo.php');
  5. $isReceiveForm = count($_POST) > 0;
  6. $isIdentify = false;
  7. $message = '';
  8. if ($isReceiveForm) {
  9. $isReceiveData =
  10. isset($_POST['identify'],
  11. $_POST['hash']);
  12. if (!$isReceiveData) {
  13. $message = 'Ingrese sus datos';
  14. }
  15. }
  16. //The user send correctly indentify and hash
  17. if ($isReceiveForm &&
  18. $isReceiveData) {
  19. //index properties
  20. $post = new Post($db);
  21. $post->identify = $_POST['identify'];
  22. $post->hash = hash('sha512', $_POST['hash']);
  23. $isIdentify = $post->identify();
  24. }
  25. //Is identify user
  26. if ($isIdentify) {
  27. // expire in a year
  28. setcookie('identify', $_POST['identify'], time()+29808000, "/");
  29. setcookie('hash', hash('sha512', $_POST['hash']), time()+29808000, "/");
  30. }
  31. // WELCOME
  32. if ($isIdentify &&
  33. !$isReceiveForm) {
  34. $message = 'Bienvenido';
  35. }
  36. // RETYPE YOUR DATA
  37. if (!$isIdentify && $isReceiveForm) {
  38. $message = 'Reingrese sus datos correctamente';
  39. }
  40. //Is not identify user
  41. if (!$isIdentify) {
  42. //DECLARE FORM VARIABLES
  43. $smarty->assign('identify', '');
  44. $smarty->assign('hash', '');
  45. $smarty->assign('message', $message);
  46. $page = isset($_GET['page']) ? $_GET['page'] : 'login';
  47. $smarty->display("templates/{$page}.tpl");
  48. return;
  49. }
  50. //SUPERUSER PROCESS
  51. $isSuperUser = $post->is_super_user();
  52. //is_super_user process
  53. if ($isSuperUser) {
  54. header('Location: users.php?page=read');
  55. }
  56. $isLibreTubeUser = !$isSuperUser;
  57. if ($isLibreTubeUser) {
  58. // Go to exclusive videoteca area
  59. header('Location: /');
  60. }
  61. ?>