A tumblelog CMS built on AJAX, PHP and MySQL.

user.class.php 4.5KB

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