Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.76 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Revolution;
  4. if(!defined('IN_INDEX')) { die('Sorry, you cannot access this file.'); }
  5. class users implements iUsers
  6. {
  7.    
  8.     /*-------------------------------Authenticate-------------------------------------*/
  9.    
  10.     final public function isLogged()
  11.     {
  12.         if(isset($_SESSION['user']['id']))
  13.         {
  14.             return true;
  15.         }
  16.        
  17.         return false;
  18.     }
  19.    
  20.     /*-------------------------------Checking of submitted data-------------------------------------*/
  21.    
  22.     final public function validName($username)  
  23.     {
  24.         if(strlen($username) <= 25 && preg_match("/^[a-zA-Z0-9\.\-]+$/i", $username))      
  25.         {          
  26.             return true;       
  27.         }              
  28.        
  29.         return false;  
  30.     }      
  31.          
  32.     final public function validEmail($email)    
  33.     {      
  34.         return preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $email);  
  35.     }      
  36.    
  37.     final public function validSecKey($seckey)
  38.     {
  39.         if(is_numeric($seckey) && strlen($seckey) == 4)
  40.         {
  41.             return true;
  42.         }
  43.        
  44.         return false;
  45.     }
  46.    
  47.     final public function nameTaken($username)  
  48.     {      
  49.         global $engine;        
  50.        
  51.         if($engine->num_rows("SELECT * FROM users WHERE username = '" . $username . "' LIMIT 1") > 0)
  52.         {
  53.             return true;
  54.         }  
  55.        
  56.         return false;
  57.     }
  58.    
  59.     final public function emailTaken($email)
  60.     {
  61.         global $engine;
  62.        
  63.         if($engine->num_rows("SELECT * FROM users WHERE mail = '" . $email . "' LIMIT 1") > 0)
  64.         {
  65.             return true;
  66.         }
  67.        
  68.         return false;
  69.     }
  70.        
  71.     final public function userValidation($username, $password)
  72.     {      
  73.         global $engine;
  74.         if($engine->num_rows("SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1") > 0)
  75.         {
  76.             return true;
  77.         }  
  78.          
  79.         return false;
  80.     }      
  81.    
  82.     /*-------------------------------Stuff related to bans-------------------------------------*/
  83.    
  84. final public function isBanned($value)
  85.     {
  86.         global $engine;
  87.          
  88.         if ($engine->num_rows("SELECT * FROM bans WHERE value = '" . $value . "' AND expire >= '" . time() . "' ") > 0)
  89.         {
  90.             return true;
  91.         }
  92.  
  93.         return false;  
  94.     }  
  95.    
  96.     final public function getReason($value)
  97.     {
  98.         global $engine;
  99.         return $engine->result("SELECT reason FROM bans WHERE value = '" . $value . "' LIMIT 1");
  100.     }
  101.    
  102.     final public function hasClones($ip)
  103.     {
  104.         global $engine;
  105.         if($engine->num_rows("SELECT * FROM users WHERE ip_reg = '" . $_SERVER['REMOTE_ADDR'] . "'") == 199999)
  106.         {
  107.             return true;
  108.         }
  109.        
  110.         return false;
  111.     }
  112.    
  113.     /*-------------------------------Login or Register user-------------------------------------*/
  114.    
  115.     final public function register()
  116.     {
  117.         global $core, $template, $_CONFIG;
  118.        
  119.         if(isset($_POST['register']))
  120.         {
  121.             unset($template->form->error);
  122.            
  123.             $template->form->setData();
  124.                
  125.             if($this->validName($template->form->reg_username))
  126.             {
  127.                 if(!$this->nameTaken($template->form->reg_username))
  128.                 {
  129.                     if($this->validEmail($template->form->reg_email))
  130.                     {
  131.                         if(!$this->emailTaken($template->form->reg_email))
  132.                         {
  133.                             if(strlen($template->form->reg_password) > 6)
  134.                             {
  135.                                 if($template->form->reg_password == $template->form->reg_rep_password)
  136.                                 {
  137.                                     if(isset($template->form->reg_seckey))
  138.                                     {
  139.                                         if($this->validSecKey($template->form->reg_seckey))
  140.                                         {
  141.                                             //Continue
  142.                                         }
  143.                                         else
  144.                                         {
  145.                                             $template->form->error = 'Secret key moet maar 4 nummers zijn.';
  146.                                             return;
  147.                                         }
  148.                                     }
  149.                                     if($this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  150.                                     {
  151.                                         if(!$this->hasClones($_SERVER['REMOTE_ADDR']))
  152.                                         {
  153.                                             if (@$_POST['captcha'] == $_SESSION['security_number'])
  154.                                             {  
  155.                                             if(!isset($template->form->reg_gender)) { $template->form->reg_gender = 'M'; }
  156.                                             if(!isset($template->form->reg_figure)) { $template->form->reg_figure = $_CONFIG['hotel']['figure']; }
  157.                                        
  158.                                             $this->addUser($template->form->reg_username, $core->hashed($template->form->reg_password), $template->form->reg_email, $_CONFIG['hotel']['motto'], $_CONFIG['hotel']['credits'], $_CONFIG['hotel']['pixels'], 1, $template->form->reg_figure, $template->form->reg_gender, $core->hashed($template->form->reg_key));
  159.                            
  160.                                             $this->turnOn($template->form->reg_username);
  161.                                    
  162.                                             header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  163.                                             exit;
  164.                                         }
  165.                                         else
  166.                                         {
  167.                                             $template->form->error = 'Foute captcha.';
  168.                                         }
  169.                                         }
  170.                                     }
  171.                                     else
  172.                                     {
  173.                                         $template->form->error = 'Sorry, het lijkt er op dat je bent verbannen.<br />';
  174.                                         $template->form->error .= 'Reden: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  175.                                         return;
  176.                                     }
  177.                                 }
  178.                                 else   
  179.                                 {
  180.                                     $template->form->error = 'Wachtwoorden zijn niet gelijk.';
  181.                                     return;
  182.                                 }
  183.  
  184.                             }
  185.                             else
  186.                             {
  187.                                 $template->form->error = 'Wachtwoord moet meer dan 6 karakters hebben.';
  188.                                 return;
  189.                             }
  190.                         }
  191.                         else
  192.                         {
  193.                             $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> is al geregistreerd.';
  194.                             return;
  195.                         }
  196.                     }
  197.                     else
  198.                     {
  199.                         $template->form->error = 'Email is niet geldig.';
  200.                         return;
  201.                     }
  202.                 }
  203.                 else
  204.                 {
  205.                     $template->form->error = 'Gebruikersnaam is al geregistreerd';
  206.                     return;
  207.                 }
  208.             }
  209.             else
  210.             {
  211.                 $template->form->error = 'Gebruikersnaam is niet geldig.';
  212.                 return;
  213.             }
  214.         }
  215.     }  
  216.    
  217.     final public function login()
  218.     {
  219.         global $template, $_CONFIG, $core;
  220.        
  221.         if(isset($_POST['login']))
  222.         {
  223.             $template->form->setData();
  224.             unset($template->form->error);
  225.            
  226.             if($this->nameTaken($template->form->log_username))
  227.             {
  228.                 if($this->isBanned($template->form->log_username) == false || $this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  229.                 {
  230.                     if($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password)))
  231.                     {
  232.                         $this->turnOn($template->form->log_username);
  233.                         $this->updateUser($_SESSION['user']['id'], 'ip_last', $_SERVER['REMOTE_ADDR']);
  234.                         $template->form->unsetData();
  235.                         header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  236.                         exit;
  237.                     }
  238.                     else
  239.                     {
  240.                         $template->form->error = 'Wachtwoord klopt niet!';
  241.                         return;
  242.                     }
  243.                 }
  244.                 else
  245.                 {
  246.                     $template->form->error = 'Je bent verbannen!<br />';
  247.                     $template->form->error .= 'Reden: ' . $this->getReason($template->form->log_username);
  248.                     return;
  249.                 }
  250.             }
  251.             else
  252.             {
  253.                 $template->form->error = 'Je naam bestaat niet!';
  254.                 return;
  255.             }
  256.         }
  257.     }
  258.    
  259.     final public function loginHK()
  260.     {
  261.         global $template, $_CONFIG, $core;
  262.        
  263.         if(isset($_POST['login']))
  264.         {  
  265.             $template->form->setData();
  266.             unset($template->form->error);
  267.            
  268.             if(isset($template->form->username) && isset($template->form->password))
  269.             {
  270.                 if($this->nameTaken($template->form->username))
  271.                 {    
  272.                     if($this->userValidation($template->form->username, $core->hashed($template->form->password)))
  273.                     {
  274.                         if(($this->getInfo($_SESSION['user']['id'], 'rank')) >= 5)
  275.                         {
  276.                             $_SESSION["in_hk"] = true;
  277.                             header("Location:".$_CONFIG['hotel']['url']."/ase/secure");
  278.                             exit;
  279.                         }
  280.                         else
  281.                         {
  282.                             $template->form->error = 'Geen toegang.';
  283.                             return;
  284.                         }
  285.                     }
  286.                     else
  287.                     {
  288.                         $template->form->error = 'Incorrect wachtwoord.';
  289.                         return;
  290.                     }      
  291.                 }
  292.                 else
  293.                 {
  294.                     $template->form->error = 'Gebruiker bestaat niet.';
  295.                     return;
  296.                 }
  297.             }
  298.    
  299.             $template->form->unsetData();
  300.         }
  301.     }  
  302.    
  303.     final public function help()
  304.     {
  305.         global $template, $_CONFIG;
  306.         $template->form->setData();
  307.        
  308.         if(isset($template->form->help))
  309.         {
  310.             $to = $_CONFIG['hotel']['email'];
  311.             $subject = "Help Raze gebruiker - " . $this->getInfo($_SESSION['user']['id'], 'username');
  312.             $body = $template->form->question;
  313.                
  314.             if (mail($to, $subject, $body))
  315.             {
  316.                 $template->form->error = 'Bericht succesvol verzonden! We zullen je zo snel mogelijk beantwoorden!';
  317.             }
  318.             else
  319.             {
  320.                  $template->form->error = 'Bericht niet verzonden.';
  321.             }
  322.         }
  323.     }
  324.  
  325.     /*-------------------------------Account settings-------------------------------------*/
  326.    
  327.     final public function updateAccount()
  328.     {
  329.         global $template, $_CONFIG, $core, $engine;
  330.        
  331.         if(isset($_POST['account']))
  332.         {
  333.        
  334.             if(isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30 && $_POST['acc_motto'] != $this->getInfo($_SESSION['user']['id'], 'motto'))
  335.             {
  336.                 $this->updateUser($_SESSION['user']['id'], 'motto', str_replace(array("{", "}"), null, $engine->secure($_POST['acc_motto'])));
  337.                 header('Location: '.$_CONFIG['hotel']['url'].'/account');
  338.                 exit;
  339.             }
  340.             else
  341.             {
  342.                 $template->form->error = 'Motto is ongeldig.';
  343.             }
  344.            
  345.             if(isset($_POST['acc_email']) && $_POST['acc_email'] != $this->getInfo($_SESSION['user']['id'], 'mail'))
  346.             {
  347.                 if($this->validEmail($_POST['acc_email']))
  348.                 {
  349.                     $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  350.                     header('Location: '.$_CONFIG['hotel']['url'].'/account');
  351.                     exit;
  352.                 }
  353.                 else
  354.                 {
  355.                     $template->form->error = 'Email is ongeldig.';
  356.                     return;
  357.                 }
  358.             }
  359.            
  360.             if(!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password']))
  361.             {
  362.                 if($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password'])))
  363.                 {
  364.                     if(strlen($_POST['acc_new_password']) >= 8)
  365.                     {
  366.                         $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  367.                         header('Location: '.$_CONFIG['hotel']['url'].'/me');
  368.                         exit;
  369.                     }
  370.                     else
  371.                     {
  372.                         $template->form->error = 'Nieuwe wachtwoord is te kort.';
  373.                         return;
  374.                     }
  375.                 }
  376.                 else
  377.                 {
  378.                     $template->form->error = 'Huidig wachtwoord is fout.';
  379.                     return;
  380.                 }
  381.             }
  382.         }      
  383.     }
  384.        
  385.        
  386.     final public function turnOn($k)
  387.     {  
  388.         $j = $this->getID($k);
  389.         $this->createSSO($j);
  390.         $_SESSION['user']['id'] = $j;  
  391.         $this->cacheUser($j);  
  392.         unset($j);
  393.     }
  394.    
  395.     /*-------------------------------Loggin forgotten-------------------------------------*/    
  396.    
  397.         final public function forgotten()
  398. {
  399. }  
  400.    
  401.     /*-------------------------------Create SSO auth_ticket-------------------------------------*/
  402.    
  403.     final public function createSSO($k)    
  404.     {      
  405.         $sessionKey = 'Malefi-'.rand(9,9999999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  406.        
  407.         $this->updateUser($k, 'auth_ticket', $sessionKey);
  408.        
  409.         unset($sessionKey);
  410.     }    
  411.        
  412.     /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  413.    
  414.     final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender, $seckey)    
  415.     {      
  416.         global $engine;                                
  417.         $sessionKey = 'Malefi-'.rand(9,9999999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  418.         $engine->query("INSERT INTO users (username, password, mail, motto, credits, activity_points, rank, look, gender, seckey, ip_last, ip_reg, account_created, last_online, auth_ticket) VALUES('" . $username . "', '" . $password . "', '" . $email . "', '" . $motto . "', '" . $credits . "', '" . $pixels . "', '" . $rank . "', '" . $figure . "', '" . $gender . "', '" . $seckey . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . time() . "', '" . time() . "', '" . $sessionKey . "')");    
  419.         unset($sessionKey);
  420.                      
  421.     }              
  422.          
  423.     final public function deleteUser($k)    
  424.     {      
  425.         global $engine;                
  426.         $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");       
  427.         $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");       
  428.         $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");  
  429.     }  
  430.        
  431.     final public function updateUser($k, $key, $value)  
  432.     {      
  433.         global $engine;                
  434.         $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  435.         $_SESSION['user'][$key] = $engine->secure($value);     
  436.     }
  437.         final public function updateIp($k, $key, $value)    
  438.     {      
  439.         global $engine;                
  440.         $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  441.         $_SESSION['user'][$key] = $engine->secure($value);     
  442.     }
  443.    
  444.     /*-------------------------------Handling user information-------------------------------------*/    
  445.    
  446.     final public function cacheUser($k)
  447.     {
  448.         global $engine;            
  449.         $userInfo = $engine->fetch_assoc("SELECT username, rank, motto, mail, credits, activity_points, look, auth_ticket, ip_last FROM users WHERE id = '" . $k . "' LIMIT 1");
  450.        
  451.         foreach($userInfo as $key => $value)
  452.         {
  453.             $this->setInfo($key, $value);
  454.         }
  455.     }  
  456.    
  457.     final public function setInfo($key, $value)
  458.     {
  459.         global $engine;
  460.         $_SESSION['user'][$key] = $engine->secure($value);
  461.     }
  462.  
  463.     final public function getInfo($k, $key)
  464.     {
  465.         global $engine;
  466.         if(!isset($_SESSION['user'][$key]))
  467.         {
  468.             $value = $engine->result("SELECT $key FROM users WHERE id = '" . $engine->secure($k) . "' LIMIT 1");
  469.             if($value != null)
  470.             {          
  471.                 $this->setInfo($key, $value);
  472.             }
  473.         }
  474.            
  475.         return $_SESSION['user'][$key];
  476.     }
  477.    
  478.    
  479.    
  480.     /*-------------------------------Get user ID or Username-------------------------------------*/
  481.    
  482.     final public function getID($k)    
  483.     {      
  484.         global $engine;        
  485.         return $engine->result("SELECT id FROM users WHERE username = '" . $engine->secure($k) . "' LIMIT 1");  
  486.     }      
  487.    
  488.     final public function getUsername($k)
  489.     {
  490.         global $engine;
  491.         return $this->getInfo($_SESSION['user']['id'], 'username');
  492.     }
  493.    
  494. }
  495. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement