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.     * CreateNewUser, if there is no such user name in user tab, creates a new dataset
  99.     *
  100.     * @uses ConnectDB::sqlSet()    
  101.     * @return void
  102.     */
  103.     private function createNewUser(){    
  104.         $this->dbObj->sqlSet("INSERT INTO {$this->_prefix}etchat_user ( etchat_username, etchat_usersex ) VALUES ( '".$this->_user."', '".$this->_gender{0}."')");
  105.         $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");
  106.         $_SESSION['etchat_'.$this->_prefix.'user_id'] = $user_neu[0][0];
  107.         $_SESSION['etchat_'.$this->_prefix.'username'] = $user_neu[0][1];
  108.         $_SESSION['etchat_'.$this->_prefix.'user_priv'] = $user_neu[0][2];
  109.         $this->status=1;
  110.     }
  111.     
  112. /**    
  113.     * UserWithPw, user name and user pw were committed from login form
  114.     *
  115.     * @return void 
  116.     */
  117.     private function userWithPw(){
  118.         if ($this->_user_exists[0][2]==md5($this->_pw)){
  119.             $_SESSION['etchat_'.$this->_prefix.'user_id'] = $this->_user_exists[0][0];
  120.             $_SESSION['etchat_'.$this->_prefix.'username'] = $this->_user_exists[0][1];
  121.             $_SESSION['etchat_'.$this->_prefix.'user_priv'] = $this->_user_exists[0][3];
  122.             if ($_SESSION['etchat_'.$this->_prefix.'user_priv']=='admin' ||
  123.                 $_SESSION['etchat_'.$this->_prefix.'user_priv']=='mod') setcookie("cookie_anzahl_logins_in_XX_sek",1);
  124.             $this->status=1;
  125.         }
  126.         else $this->status = $this->_lang->pw_falsch[0]->tagData;
  127.         
  128.     }
  129.     
  130. /**    
  131.     * UserWithoutPw, this user has a pw in db, so the status is "pw" to make a invitation in login-form to insert a pw
  132.     *
  133.     * @return void 
  134.     */
  135.     private function userWithoutPw(){
  136.         if (!empty($this->_user_exists[0][2])) {
  137.         
  138.             // if the user shpul get the invisible feeld in PW enter
  139.             $this->status = ($this->_user_exists[0][3]=="admin") ? "pw+invisible" : "pw";
  140.  
  141.         }
  142.         else {
  143.             $_SESSION['etchat_'.$this->_prefix.'user_id'] = $this->_user_exists[0][0];
  144.             $_SESSION['etchat_'.$this->_prefix.'username'] = $this->_user_exists[0][1];
  145.             $_SESSION['etchat_'.$this->_prefix.'user_priv'] = $this->_user_exists[0][3];
  146.             if ($_SESSION['etchat_'.$this->_prefix.'user_priv']=='admin' ||
  147.                 $_SESSION['etchat_'.$this->_prefix.'user_priv']=='mod') setcookie("cookie_anzahl_logins_in_XX_sek",1);
  148.             $this->status = 1;
  149.         }
  150.     }

Documentation generated on Tue, 22 Dec 2009 09:42:52 +0100 by phpDocumentor 1.4.1