Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.65 KB | None | 0 0
  1. <?php
  2. class Users
  3. {
  4.     public static $UserID;
  5.     public static $Username;
  6.     public static $UserIP;
  7.  
  8.     public function __construct()
  9.     {
  10.         self::$UserID   = (isset($_SESSION['user_id'])) ? $_SESSION['user_id'] : NULL;
  11.         self::$Username = (isset($_SESSION['user_name'])) ? $_SESSION['user_name'] : NULL;
  12.         self::$UserIP   = (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
  13.     }
  14.  
  15.     public static function setSession($id, $username)
  16.     {
  17.         self::$UserID   = $id;
  18.         self::$Username = $username;
  19.  
  20.         $_SESSION['user_id']    = $id;
  21.         $_SESSION['user_name']  = $username;
  22.     }
  23.  
  24.     public static function validateUsername($username)
  25.     {
  26.         if(preg_match('/^[a-z0-9]+$/i', $username) && strlen($username) >= 1 && strlen($username) <= 20)
  27.         {
  28.             $count = LightShot::$Database->countQuery("SELECT username FROM users WHERE username = ?", array($username));
  29.  
  30.             if($count == 0) return true;
  31.         }
  32.  
  33.         return false;
  34.     }
  35.  
  36.     public static function validatePassword($password, $password2)
  37.     {
  38.         if(strlen($password) >= 6 && $password == $password2) return true;
  39.  
  40.         return false;
  41.     }
  42.  
  43.     public static function validateEmail($username)
  44.     {
  45.         if(filter_var($email, FILTER_VALIDATE_EMAIL))
  46.         {
  47.             $count = LightShot::$Database->countQuery("SELECT mail FROM users WHERE mail = ?", array($username));
  48.  
  49.             if($count == 0) return true;
  50.         }
  51.  
  52.         return false;
  53.     }
  54.  
  55.     public static function checkDuplicates()
  56.     {
  57.         $count = LightShot::$Database->countQuery("SELECT username FROM users WHERE ip_last = ? OR WHERE ip_reg = ?", array(self::$UserIP, self::$UserIP));
  58.  
  59.         if($count >= LightShot::$Config['new_user']['max_accounts']) return false;
  60.  
  61.         return true;
  62.     }
  63.  
  64.     public static function userData($id, $key)
  65.     {
  66.         $user = LightShot::$Database->arrayQuery("SELECT {$key} FROM users WHERE id = ?", array($id));
  67.  
  68.         return $user[$key];
  69.     }
  70.  
  71.     public static function login($username, $password)
  72.     {
  73.         $user = LightShot::$Database->arrayQuery("SELECT `id`, `username`, `password` FROM `users` WHERE `username` = ? OR WHERE `mail` = ? LIMIT 1", array($username));
  74.  
  75.         if(user == null)
  76.         {
  77.             Templater::$Notice = 'Incorrect username or email address. Please double check your details and resubmit!';
  78.             return false;
  79.         }
  80.  
  81.         if($user['password'] != Site::Hash($password))
  82.         {
  83.             Templater::$Notice = 'The password you entered is incorrect. Please double check your details and resubmit!';
  84.             return false;
  85.         }
  86.  
  87.         self::setSession($user['id'], $user['username']);
  88.  
  89.         return true;
  90.     }
  91.  
  92.     public static function register($username, $password, $password2, $email)
  93.     {
  94.         if($username == null || $password == null || $password2 == null || $email == null) return false;
  95.  
  96.         if(self::checkDuplicates() == true)
  97.         {
  98.             if(self::validateUsername($username) == true)
  99.             {
  100.                 if(self::validatePassword($password, $password2) == true)
  101.                 {
  102.                     $password = Site::Hash($password);
  103.  
  104.                     $user = LightShot::$Database->query(
  105.                         "INSERT INTO `users` VALUES (NULL, ?, NULL, ?, ?, 0, ?, 0, NULL, NULL, ?, ?, ?, ?, ?, 0, 0, 0, NULL, ?, ?, NULL, ?)",
  106.                         array(
  107.                             $username,
  108.                             $password,
  109.                             $email,
  110.                             time(),
  111.                             LightShot::$Config['new_user']['motto'],
  112.                             LightShot::$Config['new_user']['look'],
  113.                             LightShot::$Config['new_user']['gender'],
  114.                             LightShot::$Config['new_user']['rank'],
  115.                             LightShot::$Config['new_user']['credits'],
  116.                             self::$UserIP,
  117.                             self::$UserIP,
  118.                             LightShot::$Config['new_user']['home_room']));
  119.                    
  120.                     $id = LightShot::$Database->getLastID();
  121.  
  122.                     $currency = LightShot::$Database->query(
  123.                         "INSERT INTO `users` VALUES (?, 0, ?), (?, 5, ?)", array(
  124.                             $id,
  125.                             LightShot::$Config['new_user']['duckets'],
  126.                             $id,
  127.                             LightShot::$Config['new_user']['diamonds']));
  128.                 }
  129.             }
  130.         }
  131.     }
  132.    
  133.     public static function CreateSSO(){
  134.       $sso_var_1 = rand(1000000, 9999999);
  135.       $sso_var_2 = str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
  136.       $ticket = strtoupper(LightShot::$Config->site_name).'/--/'.$sso_var_2.'/--/'.sha1($sso_var_1);
  137.      
  138.       LightShot::$MySQL->query('UPDATE users SET `auth_ticket` = ? WHERE `id` = ?', Array($ticket, self::$ID));
  139.      
  140.       return $ticket;
  141.     }
  142.    
  143.     public static function CheckRegDetails($username, $captcha, $captcha_entered, $email, $password, $repeat_password, $age, $gender){
  144.       /* The data inserted into this function does not need to be secured */
  145.      
  146.       if(self::UsernameOk($username) == 'true'){
  147.         if($captcha == $captcha_entered){
  148.           if(preg_match('/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i', $email) && !empty($email)){
  149.             if(LightShot::$MySQL->num_rows('SELECT null FROM users WHERE mail = ?', array($email)) == 0){
  150.               if(self::PasswordsOk($password, $repeat_password) == 'true'){
  151.                 if(true){
  152.                   if($gender == 'M' || $gender == 'F' || $gender == ''){
  153.                     if($gender == 'M' || $gender == ''){ $look = 'sh-3016-110.hd-209-2.ea-8030-85.lg-3320-92-92.ch-7285-110.hr-8623-34'; }elseif($gender == 'F'){ $look = 'sh-905-1414.hd-629-2.he-1608-92.ch-7013-81-82.hr-3625-34-40.lg-3596-83-85'; }
  154.                     /*
  155.                     * [Current verified data]
  156.                     * $username
  157.                     * $email
  158.                     * $password
  159.                     * $age
  160.                     * $gender
  161.                     * $look
  162.                     */
  163.                     if(self::InsertUser($username, $email, $password, $age, $gender, 'wa-2001-3072.ch-220-66.hd-180-1.hr-3090-1398.lg-285-82.sh-305-92')){
  164.                       if(self::Login($username, $password)){
  165.                         Templater::$Notice = 'Welcome, '.$username.', Your registry was successful your account has been created! Redirecting you now...';
  166.                         return true; //We did good
  167.                       }
  168.                     }
  169.                   }else{/*Username check failed*/ Templater::$Notice = 'Do not manipulate our forms. Thank you..'; return false; }
  170.                 }else{/*Not too young or too old*/ Templater::$Notice = 'Sorry that here you must be older than 8 years and younger than 30 years. This is due to the fact that the use of pedals is allowed, and this hotel has an explicit language. Excuse me. But if you really want to come, change your age.'; return false; }
  171.               }else{/*Password check failed*/ Templater::$Notice = self::PasswordsOk($password, $repeat_password); return false; }
  172.             }else{/*Password check failed*/ Templater::$Notice = 'Sorry, but this email address is taken. Please enter a new one.'; return false; }
  173.           }else{/*Email entered is incorrect*/ Templater::$Notice = 'This email address is invalid. Please confirm your entries and resubmit.'; return false; }
  174.         }else{/*Captcha false*/ Templater::$Notice = 'The captcha you entered is incorrect. Please try again.'; return false; }
  175.       }else{/*Username check failed*/ Templater::$Notice = self::UsernameOk($username); return false; }
  176.     }
  177.    
  178.     public static function InsertUser($username, $email, $password, $age, $gender, $look){
  179.       try{
  180.         /* Just so our passwords can not be grabbed */
  181.         $password = Site::Hash($password);
  182.         /* Just setting vars, easier to use in the query */
  183.         $coins = LightShot::$Config->default_coins;
  184.         $duckets = LightShot::$Config->default_duckets;
  185.         $rank = LightShot::$Config->default_rank;
  186.         $motto = LightShot::$Config->default_motto;
  187.         /* Insert the user */
  188.         LightShot::$MySQL->query('INSERT INTO users (username, motto, mail, password, gender, credits, pixels, account_created, rank, look, ip_register, ip_current) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
  189.         array($username, $motto, $email, $password, $gender, $coins, $duckets, time(), $rank, $look, LightShot::$ClientIP, LightShot::$ClientIP)
  190.         );
  191.         $id = LightShot::$MySQL->fetch_array('SELECT `id` FROM `users` WHERE `username` = ?', array($username))['id'];
  192.         LightShot::$MySQL->query('INSERT INTO users_currency (user_id, type, amount) VALUES (?, 0, 100)', array($id));
  193.         LightShot::$MySQL->query('INSERT INTO cms_minimail (message, date_sent, sender_look, sender_name, replied, deleted, receiver) VALUES (?, ?, ?, ?, ?, ?, ?)',
  194.         array('Welcome to '.LightShot::$Config->site_name.', we hope that you enjoy your stay!', time(), 'hr-165-34.sh-290-92.ch-215-84.hd-180-1.lg-280-64', '#'.LightShot::$Config->site_name, 0, 0, $username)
  195.         );
  196.        
  197.         return true;
  198.        
  199.       /* Error */
  200.       }catch(PDOException $error){
  201.         die('<center><h1>LightShot CMS Error:</h1><hr>Error inserting user in class.users.php on line 205</center><br><br><b>Error data:</b><br><br>'.$error);
  202.       }
  203.     }
  204.   }
  205. '';
  206. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement