A tumblelog CMS built on AJAX, PHP and MySQL.

user.class.php 4.7KB

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