create.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. include_once('../../index.php');
  3. include_once('templates/core/Smarty.class.php');
  4. $smarty = new smarty();
  5. $isCookied = isset($_COOKIE['identify'], $_COOKIE['hash']);
  6. $isReceiveForm = count($_POST) > 0;
  7. $isIdentify = false;
  8. $message = '';
  9. if ($isCookied) {
  10. //index properties
  11. $post = new Post($db);
  12. $post->identify = $_COOKIE['identify'];
  13. $post->hash = $_COOKIE['hash'];
  14. $isIdentify = $post->identify();
  15. }
  16. //Is not identify user
  17. if (!$isIdentify) {
  18. // return to login
  19. header('Location: users.php?page=login');
  20. return;
  21. }
  22. //Is superuser needed
  23. if ($isIdentify) {
  24. //SUPERUSER PROCESS
  25. $isSuperUser = $post->is_super_user();
  26. }
  27. if (!$isSuperUser) {
  28. header('Location: /');
  29. return;
  30. }
  31. if ($isReceiveForm) {
  32. $isReceiveData =
  33. isset($_POST['name'],
  34. $_POST['password']);
  35. if (!$isReceiveData) {
  36. $message = 'Ingrese todos los datos';
  37. }
  38. if ($isReceiveData) {
  39. $post = new Post($db);
  40. $post->identify = $_COOKIE['identify'];
  41. $post->hash = $_COOKIE['hash'];
  42. $post->rol = isset($_POST['rol']) ? $_POST['rol'] : 0;
  43. $post->name = $_POST['name'];
  44. $post->password = hash ( 'sha512', $_POST['password']);
  45. //is duplicate user
  46. if (!$post->is_new_user()) {
  47. $message = 'Usuario ya existe intente otro nombre de usuario.';
  48. }
  49. $message = 'TODO GENIAL';
  50. $isCreated = $post->create();
  51. //create user
  52. if ($isCreated) {
  53. header('Location: users.php?page=read');
  54. }
  55. if (!$isCreated) {
  56. $message = 'Algo fallo en `$isCreated`';
  57. }
  58. }
  59. }
  60. //DECLARE FORM VARIABLES
  61. $smarty->assign('rol', 1);
  62. $smarty->assign('name', '');
  63. $smarty->assign('password', '');
  64. $smarty->assign('message', $message);
  65. $smarty->display("templates/{$_GET['page']}.tpl");
  66. ?>