Source for file UserCheckerAndInserter.class.php

Documentation is available at UserCheckerAndInserter.class.php

  1. <?php
  2. /**
  3.  * Class UserCheckerAndInserter, checks the user and insert him/her to db, if possible
  4.  *
  5.  * LICENSE: CREATIVE COMMONS PUBLIC LICENSE  "Namensnennung — Nicht-kommerziell 2.0"
  6.  *
  7.  * @copyright  2009 <SEDesign />
  8.  * @license    http://creativecommons.org/licenses/by-nc/2.0/de/
  9.  * @version    $3.0.6$
  10.  * @link       http://www.sedesign.de/de_produkte_chat-v3.html
  11.  * @since      File available since Alpha 1.0
  12.  */
  13.  
  14. {
  15.     /**
  16.     * DB-Connection Obj
  17.     * @var ConnectDB 
  18.     */
  19.     private $dbObj;
  20.     
  21.     /**
  22.     * array with all user data
  23.     * @var array 
  24.     */
  25.     protected $_user_exists;
  26.     
  27.     /**
  28.     * user name
  29.     * @var string 
  30.     */
  31.     protected $_user;
  32.     
  33.     /**
  34.     * user pw
  35.     * @var string 
  36.     */
  37.     protected $_pw;
  38.     
  39.     /**
  40.     * user sex
  41.     * @var string 
  42.     */
  43.     protected $_gender;
  44.     
  45.     /**
  46.     * XMLParser Obj
  47.     * @var XMLParser 
  48.     */
  49.     protected $_lang;
  50.     
  51.     /**
  52.     * this var is a status var and will be occupied with different values in subjection of needs, so it can get value "1" for ok, or just an other error message
  53.     * @var string 
  54.     */
  55.     public $status;
  56.     
  57.     /**
  58.     * Constructor
  59.     *
  60.     * @param  ConnectDB $dbObj, Obj with the db connection handler
  61.     * @param  array $user_exists 
  62.     * @param  string $user 
  63.     * @param  string $pw 
  64.     * @param  string $gender 
  65.     * @param  XMLParser $lang 
  66.     * @uses ConnectDB::sqlSet()
  67.     * @return void 
  68.     */
  69.     public function __construct ($dbObj$user_exists$user$pw$gender$lang)
  70.         
  71.         // call parent Constructor from class EtChatConfig
  72.         parent::__construct();
  73.         
  74.         $this->dbObj = $dbObj;
  75.         
  76.         // set the class vars
  77.         $this->_user_exists=$user_exists;
  78.         $this->_user=$user;
  79.         $this->_pw=$pw;
  80.         $this->_gender=$gender;
  81.         $this->_lang=$lang;
  82.         
  83.         // if the user name is just exists in the user table
  84.         if (is_array($this->_user_exists)){
  85.             
  86.             // update needed user params
  87.             $this->dbObj->sqlSet("UPDATE {$this->_prefix}etchat_user SET etchat_usersex = '".$this->_gender{0}."' WHERE etchat_user_id = ".$this->_user_exists[0][0]);
  88.             
  89.             // need pw input?
  90.             if ($this->_pw==""$this->userWithoutPw();
  91.             else $this->userWithPw();
  92.         }
  93.         else $this->createNewUser();
  94.         
  95.         
  96.     }
  97.     
  98.     /**
  99.     * CreateNewUser, if there is no such user name in user tab, creates a new dataset
  100.     *
  101.     * @uses ConnectDB::sqlSet()    
  102.     * @return void
  103.     */
  104.     private function createNewUser(){    
  105.         $this->dbObj->sqlSet("INSERT INTO {$this->_prefix}etchat_user ( etchat_username, etchat_usersex ) VALUES ( '".$this->_user."', '".$this->_gender{0}."')");
  106.         $user_neu=$this->dbObj->sqlGet("SELECT etchat_user_id, etchat_username, etchat_userprivilegien FROM {$this->_prefix}etchat_user WHERE etchat_username = '".$this->_user."' LIMIT 1");
  107.         $_SESSION['etchat_'.$this->_prefix.'user_id'] = $user_neu[0][0];
  108.         $_SESSION['etchat_'.$this->_prefix.'username'] = $user_neu[0][1];
  109.         $_SESSION['etchat_'.$this->_prefix.'user_priv'] = $user_neu[0][2];
  110.         $this->status=1;
  111.     }
  112.     
  113. /**    
  114.     * UserWithPw, user name and user pw were committed from login form
  115.     *
  116.     * @return void 
  117.     */
  118.     private function userWithPw(){
  119.         if ($this->_user_exists[0][2]==md5($this->_pw)){
  120.             $_SESSION['etchat_'.$this->_prefix.'user_id'] = $this->_user_exists[0][0];
  121.             $_SESSION['etchat_'.$this->_prefix.'username'] = $this->_user_exists[0][1];
  122.             $_SESSION['etchat_'.$this->_prefix.'user_priv'] = $this->_user_exists[0][3];
  123.             if ($_SESSION['etchat_'.$this->_prefix.'user_priv']=='admin' ||
  124.                 $_SESSION['etchat_'.$this->_prefix.'user_priv']=='mod') setcookie("cookie_anzahl_logins_in_XX_sek",1);
  125.             $this->status=1;
  126.         }
  127.         else $this->status = $this->_lang->pw_falsch[0]->tagData;
  128.         
  129.     }
  130.     
  131. /**    
  132.     * UserWithoutPw, this user has a pw in db, so the status is "pw" to make a invitation in login-form to insert a pw
  133.     *
  134.     * @return void 
  135.     */
  136.     private function userWithoutPw(){
  137.         if (!empty($this->_user_exists[0][2])) {
  138.         
  139.             // if the user shpul get the invisible feeld in PW enter
  140.             $this->status = ($this->_user_exists[0][3]=="admin") ? "pw+invisible" : "pw";
  141.  
  142.         }
  143.         else {
  144.             $_SESSION['etchat_'.$this->_prefix.'user_id'] = $this->_user_exists[0][0];
  145.             $_SESSION['etchat_'.$this->_prefix.'username'] = $this->_user_exists[0][1];
  146.             $_SESSION['etchat_'.$this->_prefix.'user_priv'] = $this->_user_exists[0][3];
  147.             if ($_SESSION['etchat_'.$this->_prefix.'user_priv']=='admin' ||
  148.                 $_SESSION['etchat_'.$this->_prefix.'user_priv']=='mod') setcookie("cookie_anzahl_logins_in_XX_sek",1);
  149.             $this->status = 1;
  150.         }
  151.     }

Documentation generated on Thu, 05 May 2011 14:05:59 +0000 by phpDocumentor 1.4.3