A tumblelog CMS built on AJAX, PHP and MySQL.

user.class.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /* ===========================
  3. gelato CMS development version
  4. http://www.gelatocms.com/
  5. gelato CMS is a free software licensed under GPL (General public license)
  6. =========================== */
  7. ?>
  8. <?php
  9. require_once("configuration.class.php");
  10. class user extends Conexion_Mysql {
  11. var $conf;
  12. function user() {
  13. parent::Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  14. $this->conf = new configuration();
  15. }
  16. function isAdmin() {
  17. if(isset($_COOKIE["gelato_cookie"]) && $_COOKIE["gelato_cookie"] && $_COOKIE["gelato_cookie"]!="") {
  18. $galleta = explode(",",$_COOKIE["gelato_cookie"]);
  19. if ($this->validateUser($galleta[1],$galleta[2])) {
  20. $_SESSION["user_id"]=$galleta[0];
  21. $_SESSION["user_login"]=$galleta[1];
  22. } else {
  23. $_SESSION["user_id"]="";
  24. $_SESSION["user_login"]="";
  25. unset($_SESSION["user_id"]);
  26. unset($_SESSION["user_login"]);
  27. }
  28. }
  29. if (isset($_SESSION["user_id"]) && isset($_SESSION["user_login"])) {
  30. return true;
  31. }
  32. return false;
  33. }
  34. function validateUser($user="", $password="") {
  35. if ($this->ejecutarConsulta("SELECT id_user, login, password FROM ".$this->conf->tablePrefix."users WHERE login='".$user."' AND password='".$password."'")) {
  36. if ($this->contarRegistros()>0) {
  37. $register=$this->obtenerRegistro();
  38. $_SESSION['user_id']=$register["id_user"];
  39. $_SESSION['user_login']=$register["login"];
  40. if (isset($_POST["save_pass"])) {
  41. $cookie_life = 60*24*3600;
  42. setcookie("gelato_cookie",$register["id_user"].",".$register["login"].",".$register["password"],time()+$cookie_life);
  43. }
  44. return true;
  45. } else {
  46. return false;
  47. }
  48. } else {
  49. return false;
  50. }
  51. }
  52. function closeSession() {
  53. $_SESSION = array();
  54. $_COOKIE["gelato_cookie"]="";
  55. setcookie("gelato_cookie","",time()-3600,'/','',0);
  56. setcookie("gelato_cookie","",0);
  57. unset($_COOKIE["gelato_cookie"]);
  58. unset($_COOKIE[session_name()]);
  59. if (session_destroy()) {
  60. return true;
  61. } else {
  62. return false;
  63. }
  64. }
  65. function userExist($user="") {
  66. if ($this->ejecutarConsulta("SELECT * FROM ".$this->conf->tablePrefix."users WHERE login='".$user."'")) {
  67. if ($this->contarRegistros()>0) {
  68. return true;
  69. } else {
  70. return false;
  71. }
  72. }
  73. }
  74. function addUser($fieldsArray) {
  75. if ($this->ejecutarConsulta("SELECT id_user FROM ".$this->conf->tablePrefix."users WHERE login='".$fieldsArray['login']."'")) {
  76. if ($this->contarRegistros()==0) {
  77. if ($this->insertarDeFormulario($this->conf->tablePrefix."users", $fieldsArray)) {
  78. $this->confirmationEmail($fieldsArray['email'], $fieldsArray['login'], $fieldsArray['password']);
  79. header("Location: ".$this->conf->urlGelato."/admin/admin.php?added=true");
  80. die();
  81. } else {
  82. header("Location: ".$this->conf->urlGelato."/admin/admin.php?error=2&des=".$this->merror);
  83. die();
  84. }
  85. } else {
  86. header("Location: ".$this->conf->urlGelato."/admin/admin.php?error=1");
  87. die();
  88. }
  89. }
  90. }
  91. function modifyUser($fieldsArray, $id_user) {
  92. if ($this->modificarDeFormulario($this->conf->tablePrefix."users", $fieldsArray, "id_user=$id_user")) {
  93. header("Location: ".$this->conf->urlGelato."/admin/admin.php?modified=true");
  94. die();
  95. } else {
  96. header("Location: ".$this->conf->urlGelato."/admin/admin.php?error=2&des=".$this->merror);
  97. die();
  98. }
  99. }
  100. function deleteUser($idUser) {
  101. $this->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."users WHERE id_user=".$idUser);
  102. }
  103. function getUsers($show="10", $from="0") {
  104. $sqlStr = "select * from ".$this->conf->tablePrefix."users ORDER BY id_user DESC LIMIT $from,$show";
  105. $this->ejecutarConsulta($sqlStr);
  106. return $this->mid_consulta;
  107. }
  108. function getUserByID($idUser) {
  109. if ($this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."users where id_user=".$idUser)) {
  110. if ($this->contarRegistros()>0) {
  111. return $registro=$this->obtenerRegistro();
  112. } else {
  113. return false;
  114. }
  115. }
  116. }
  117. function confirmationEmail($email="", $user="", $password="") {
  118. $msg = "<font face=verdana><em><font size=2>Account information on <strong>gelato CMS</strong></font></em><br/><br/>";
  119. $msg .= "<font size=1>Username: <strong>".$user."</strong><br/><br/>";
  120. $msg .= "Password: <strong>".$password."</strong><br/><br/>";
  121. $msg .= "<em>Don't tell your password to anybody!!</em><br/><br/></font>";
  122. sendMail($email, "Register conformation on gelato CMS", $msg, "no-reply@gelatocms.com");
  123. }
  124. }
  125. ?>