Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 12th, 2011  |  syntax: PHP  |  size: 4.04 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. class User_model extends CI_Model {
  3.    
  4.     public $userID = '';
  5.     public $verifyHash = '';
  6.    
  7.     function __constructor()
  8.     {
  9.         parent :: __construct();
  10.     }
  11.    
  12.     function registerUser($username, $password, $email, $firstName, $lastName, $registrationKey)
  13.     {
  14.         function GenPassHash($logPass)
  15.         {
  16.                 $usersalt = substr(md5(uniqid(rand(), true)), 0, 11);
  17.                 $encPass = sha1($logPass);
  18.                 $sltPass = $encPass . $usersalt;$encSPass = sha1($sltPass);
  19.                 $passArray = array($encSPass,$usersalt);
  20.                 return $passArray;
  21.         }
  22.        
  23.         function myDomainName() {
  24.                 $my_domain = $_SERVER['HTTP_HOST'];
  25.                 $my_domain = str_replace('www.', '', $my_domain);
  26.                 return $my_domain;
  27.         }
  28.                
  29.         $password = GenPassHash($password);
  30.        
  31.         $query_str = "INSERT INTO kowmanager_users (username, password, password2, email, firstName, lastName, accessLevelID) VALUES (?, ?, ?, ?, ?, ?, ?)";
  32.         $this->db->query($query_str, array($username, $password[0], $password[1], $email, $firstName, $lastName, '1',));
  33.        
  34.         $id = $this->db->insert_id();
  35.        
  36.         $this->db->select_max('userID');
  37.         $query = $this->db->get('kowmanager_users');
  38.         $row = $query->row();
  39.         $userID = $row->userID;
  40.  
  41.         $userID = $userID + 1;
  42.        
  43.         $data = array('userID' => $userID);
  44.        
  45.         $where = "id = '".$id."'";
  46.        
  47.         $str = $this->db->update_string('kowmanager_users', $data, $where);
  48.         $my_update = $this->db->query($str);
  49.        
  50.         $myMD5string = $userID.$email.$registrationKey;
  51.         $verifyHash = md5($myMD5string);
  52.        
  53.         function getRealIPAddress()
  54.         {
  55.             if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
  56.             {
  57.                 $ip=$_SERVER['HTTP_CLIENT_IP'];
  58.             }
  59.             elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
  60.             {
  61.                 $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  62.             }
  63.             else
  64.             {
  65.                 $ip=$_SERVER['REMOTE_ADDR'];
  66.             }
  67.             return $ip;
  68.         }
  69.        
  70.         $query_str = "INSERT INTO kowmanager_users_registrations (userID, registrationDate, registrationKey, verifyHash, ipAddress) VALUES (?, ?, ?, ?, ?)";
  71.         $this->db->query($query_str, array($userID, date('Y-m-d H:i:s'), $registrationKey, $verifyHash, getRealIPAddress()));
  72.     }
  73.    
  74.     function confirmRegistration($registrationKey)
  75.     {
  76.         $query_str = "SELECT userID kowmanager_users_registrations WHERE registrationKey = ?";
  77.         $result = $this->db->query($query_str, $registrationKey);
  78.        
  79.         $row = $query->row();
  80.         $userID = $row->userID;
  81.        
  82.         if ($result->num_rows() == 1)
  83.         {
  84.             $query_str = "UPDATE kowmanager_users_registrations SET registrationKey = '' WHERE registrationKey = ?";
  85.             $this->db->query($query_str, $registrationKey);
  86.            
  87.             $query_str = "UPDATE kowmanager_users SET statusID = '2' WHERE userID = ?";
  88.             $this->db->query($query_str, $userID);
  89.            
  90.             return true;
  91.         }
  92.         else
  93.         {
  94.             return false;
  95.         }
  96.     }
  97.    
  98.     function checkExistsUsername($username)
  99.     {
  100.         $query_str = "SELECT username FROM kowmanager_users WHERE username = ?";
  101.         $result = $this->db->query($query_str, $username);
  102.        
  103.         if ($result->num_rows() > 0)
  104.         {
  105.             return true;
  106.         }  
  107.         else
  108.         {
  109.             return false;
  110.         }
  111.        
  112.     }
  113.    
  114.     function checkExistsEmail($email)
  115.     {
  116.         $query_str = "SELECT email FROM kowmanager_users WHERE email = ?";
  117.         $result = $this->db->query($query_str, $email);
  118.        
  119.         if ($result->num_rows() > 0)
  120.         {
  121.             return true;
  122.         }  
  123.         else
  124.         {
  125.             return false;
  126.         }
  127.        
  128.     }
  129.    
  130. }