A tumblelog CMS built on AJAX, PHP and MySQL.

user.class.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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='".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. if ($this->insertarDeFormulario($this->conf->tablePrefix."users", $fieldsArray)) {
  74. $this->confirmationEmail($fieldsArray['email'], $fieldsArray['login'], $fieldsArray['password']);
  75. header("Location: ".$this->conf->urlGelato."/admin/admin.php?added=true");
  76. die();
  77. } else {
  78. header("Location: ".$this->conf->urlGelato."/admin/admin.php?error=2&des=".$this->merror);
  79. die();
  80. }
  81. } else {
  82. header("Location: ".$this->conf->urlGelato."/admin/admin.php?error=1");
  83. die();
  84. }
  85. }
  86. }
  87. function modifyUser($fieldsArray, $id_user) {
  88. if ($this->modificarDeFormulario($this->conf->tablePrefix."users", $fieldsArray, "id_user=$id_user")) {
  89. header("Location: ".$this->conf->urlGelato."/admin/admin.php?modified=true");
  90. die();
  91. } else {
  92. header("Location: ".$this->conf->urlGelato."/admin/admin.php?error=2&des=".$this->merror);
  93. die();
  94. }
  95. }
  96. function deleteUser($idUser) {
  97. $this->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."users WHERE id_user=".$idUser);
  98. }
  99. function getUsers($show="10", $from="0") {
  100. $sqlStr = "select * from ".$this->conf->tablePrefix."users ORDER BY id_user DESC LIMIT $from,$show";
  101. $this->ejecutarConsulta($sqlStr);
  102. return $this->mid_consulta;
  103. }
  104. function getUserByID($idUser) {
  105. if ($this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."users where id_user=".$idUser)) {
  106. if ($this->contarRegistros()>0) {
  107. return $registro=$this->obtenerRegistro();
  108. } else {
  109. return false;
  110. }
  111. }
  112. }
  113. function confirmationEmail($email="", $user="", $password="") {
  114. $msg = "<font face=verdana><em><font size=2>Account information on <strong>gelato CMS</strong></font></em><br/><br/>";
  115. $msg .= "<font size=1>Username: <strong>".$user."</strong><br/><br/>";
  116. $msg .= "Password: <strong>".$password."</strong><br/><br/>";
  117. $msg .= "<em>Don't tell your password to anybody!!</em><br/><br/></font>";
  118. sendMail($email, "Register conformation on gelato CMS", $msg, "no-reply@gelatocms.com");
  119. }
  120. }
  121. ?>