Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Revolution;
- if(!defined('IN_INDEX')) { die('Sorry, you cannot access this file.'); }
- if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
- $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
- }
- class users implements iUsers
- {
- /*-------------------------------Authenticate-------------------------------------*/
- final public function isLogged()
- {
- if(isset($_SESSION['user']['id']))
- {
- return true;
- }
- return false;
- }
- /*-------------------------------Checking of submitted data-------------------------------------*/
- final public function validName($username)
- {
- if(strlen($username) <= 25 && preg_match("/^[a-zA-Z0-9]+$/", $username))
- {
- return true;
- }
- return false;
- }
- final public function validEmail($email)
- {
- return preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $email);
- }
- final public function validSecKey($seckey)
- {
- if(is_numeric($seckey) && strlen($seckey) == 4)
- {
- return true;
- }
- return false;
- }
- final public function nameTaken($username)
- {
- global $engine;
- if($engine->num_rows("SELECT * FROM users WHERE username = '" . $username . "' LIMIT 1") > 0)
- {
- return true;
- }
- return false;
- }
- final public function emailTaken($email)
- {
- global $engine;
- if($engine->num_rows("SELECT * FROM users WHERE mail = '" . $email . "' LIMIT 1") > 0)
- {
- return true;
- }
- return false;
- }
- final public function userValidation($username, $password)
- {
- global $engine;
- if($engine->num_rows("SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1") > 0)
- {
- return true;
- }
- return false;
- }
- /*-------------------------------Stuff related to bans-------------------------------------*/
- final public function isBanned($value)
- {
- global $engine;
- if ($engine->num_rows("SELECT * FROM bans WHERE value = '" . $value . "' AND expire >= '" . time() . "' ") > 0)
- {
- return true;
- }
- return false;
- }
- final public function getReason($value)
- {
- global $engine;
- return $engine->result("SELECT reason FROM bans WHERE value = '" . $value . "' LIMIT 1");
- }
- final public function hasClones($ip)
- {
- global $engine;
- if($engine->num_rows("SELECT * FROM users WHERE ip_last = '" . $_SERVER['REMOTE_ADDR'] . "'") >= 3)
- {
- return true;
- }
- return false;
- }
- /*-------------------------------Login or Register user-------------------------------------*/
- final public function register()
- {
- global $core, $template, $_CONFIG;
- if(isset($_POST['register']))
- {
- unset($template->form->error);
- $template->form->setData();
- if($this->validName($template->form->reg_username))
- {
- if(!$this->nameTaken($template->form->reg_username))
- {
- if($this->validEmail($template->form->reg_email))
- {
- if(!$this->emailTaken($template->form->reg_email))
- {
- if(strlen($template->form->reg_password) > 6)
- {
- if($template->form->reg_password == $template->form->reg_rep_password)
- {
- if(isset($template->form->reg_seckey))
- {
- if($this->validSecKey($template->form->reg_seckey))
- {
- //Continue
- }
- else
- {
- $template->form->error = 'Secret key must only have 4 numbers';
- return;
- }
- }
- if($this->isBanned($_SERVER['REMOTE_ADDR']) == false)
- {
- if(!$this->hasClones($_SERVER['REMOTE_ADDR']))
- {
- if(!isset($template->form->reg_gender)) { $template->form->reg_gender = 'M'; }
- if(!isset($template->form->reg_figure)) { $template->form->reg_figure = $_CONFIG['hotel']['figure']; }
- $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));
- $this->turnOn($template->form->reg_username);
- if(isset($template->form->reg_referrer) && $template->form->reg_referrer != "") {
- $this->referUser($template->form->reg_referrer);
- }
- header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
- exit;
- }
- else
- {
- $template->form->error = 'Извините, но вы не можете зарегистрировать более чем в 3 раза!';
- }
- }
- else
- {
- $template->form->error = 'Извините, кажется Вы забанены по IP<br />';
- $template->form->error .= 'Причина: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
- return;
- }
- }
- else
- {
- $template->form->error = 'Пороли не совпадают. Попробуйте еще раз';
- return;
- }
- }
- else
- {
- $template->form->error = 'Пароль должен содержать не менее 6 цифр/букв';
- return;
- }
- }
- else
- {
- $template->form->error = 'Электронная почта: <b>' . $template->form->reg_email . '</b> уже зарегистрирована';
- return;
- }
- }
- else
- {
- $template->form->error = 'Электронная почта не действительна';
- return;
- }
- }
- else
- {
- $template->form->error = 'Имя пользователя уже зарегистрировано';
- return;
- }
- }
- else
- {
- $template->form->error = 'Имя пользователя не действительно';
- return;
- }
- }
- }
- final public function login()
- {
- global $template, $_CONFIG, $core;
- if(isset($_POST['login']))
- {
- $template->form->setData();
- unset($template->form->error);
- if($this->nameTaken($template->form->log_username))
- {
- if($this->isBanned($_SERVER['REMOTE_ADDR']) == false)
- {
- if($this->isBanned($template->form->log_username) == false)
- {
- if($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password)))
- {
- $this->turnOn($template->form->log_username);
- $this->updateUser($_SESSION['user']['id'], 'ip_last', $_SERVER['REMOTE_ADDR']);
- $template->form->unsetData();
- header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
- exit;
- }
- else
- {
- $template->form->error = 'Детали не совпадают';
- return;
- }
- }
- else
- {
- $template->form->error = 'Извините, кажется этот пользователь забанен<br />';
- $template->form->error .= 'Причина: ' . $this->getReason($template->form->log_username);
- return;
- }
- }
- else
- {
- $template->form->error = 'Извините, кажется что этот IP забанен<br />';
- $template->form->error .= 'Причина: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
- return;
- }
- }
- else
- {
- $template->form->error = 'Имя пользователя не существует';
- return;
- }
- }
- }
- final public function loginHK()
- {
- global $template, $_CONFIG, $core;
- if(isset($_POST['login']))
- {
- $template->form->setData();
- unset($template->form->error);
- if(isset($template->form->username) && isset($template->form->password))
- {
- if($this->nameTaken($template->form->username))
- {
- if($this->userValidation($template->form->username, $core->hashed($template->form->password)))
- {
- if(($this->getInfo($_SESSION['user']['id'], 'rank', true)) >= 8)
- {
- $_SESSION["in_hk"] = true;
- header("Location:".$_CONFIG['hotel']['url']."/ase/dash");
- exit;
- }
- else
- {
- $template->form->error = 'Incorrect access level';
- return;
- }
- }
- else
- {
- $template->form->error = 'Incorrect password';
- return;
- }
- }
- else
- {
- $template->form->error = 'User does not exist';
- return;
- }
- }
- $template->form->unsetData();
- }
- }
- final public function help()
- {
- global $template, $_CONFIG;
- $template->form->setData();
- if(isset($template->form->help))
- {
- $to = $_CONFIG['hotel']['email'];
- $subject = "Help from RevCMS user - " . $this->getInfo($_SESSION['user']['id'], 'username');
- $body = $template->form->question;
- if (mail($to, $subject, $body))
- {
- $template->form->error = 'Message successfully sent! We will answer you shortly!';
- }
- else
- {
- $template->form->error = 'Message delivery failed';
- }
- }
- }
- /*-------------------------------Account settings-------------------------------------*/
- final public function updateAccount()
- {
- global $template, $_CONFIG, $core, $engine;
- if(isset($_POST['account']))
- {
- if(!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password']))
- {
- if($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password'])))
- {
- if($_POST['acc_new_password'] != $_POST['acc_rep_password']) {
- $template->form->error = 'The passwords you typed do not match!';
- return;
- }
- if(strlen($_POST['acc_new_password']) >= 6)
- {
- $template->form->error = 'Your password has been successfully updated';
- $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
- header('Location: '.$_CONFIG['hotel']['url'].'/logout');
- exit;
- }
- else
- {
- $template->form->error = 'The password you entered is too short';
- return;
- }
- }
- else
- {
- $template->form->error = 'The password you entered is incorrect';
- return;
- }
- }
- }
- }
- final public function turnOn($k)
- {
- $j = $this->getID($k);
- $this->createSSO($j);
- $_SESSION['user']['id'] = $j;
- $this->cacheUser($j);
- unset($j);
- }
- /*-------------------------------Create SSO auth_ticket-------------------------------------*/
- final public function createSSO($k)
- {
- global $engine;
- $sessionKey = 'RevCMS-' . rand(9, 9999999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
- if($engine->num_rows("SELECT * FROM user_auth_ticket WHERE user_id = '" . $k . "' LIMIT 1") > 0) {
- $engine->query("UPDATE user_auth_ticket SET auth_ticket = '" . $sessionKey . "' WHERE user_id = '" . $k . "'");
- } else {
- $engine->query("INSERT INTO user_auth_ticket (user_id, auth_ticket) VALUES ('" . $k . "', '" . $sessionKey ."')");
- }
- return $sessionKey;
- unset($sessionKey);
- }
- /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
- final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender, $seckey)
- {
- global $engine;
- $sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
- $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 . "')");
- unset($sessionKey);
- }
- final public function deleteUser($k)
- {
- global $engine;
- $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
- $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
- $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
- }
- final public function updateUser($k, $key, $value)
- {
- global $engine;
- $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
- $_SESSION['user'][$key] = $engine->secure($value);
- }
- /*-------------------------------Handling user information-------------------------------------*/
- final public function cacheUser($k)
- {
- global $engine;
- $userInfo = $engine->fetch_assoc("SELECT username, rank, motto, mail, credits, activity_points, look, auth_ticket, ip_last FROM users WHERE id = '" . $k . "' LIMIT 1");
- foreach($userInfo as $key => $value)
- {
- $this->setInfo($key, $value);
- }
- }
- final public function setInfo($key, $value)
- {
- global $engine;
- $_SESSION['user'][$key] = $engine->secure($value);
- }
- final public function getInfo($k, $key, $straight = false)
- {
- global $engine;
- if($straight == true || !isset($_SESSION['user'][$key]))
- {
- $value = $engine->result("SELECT $key FROM users WHERE id = '" . $engine->secure($k) . "' LIMIT 1");
- if($value != null)
- {
- $this->setInfo($key, $value);
- }
- }
- return $_SESSION['user'][$key];
- }
- /*-------------------------------Get user ID or Username-------------------------------------*/
- final public function getID($k)
- {
- global $engine;
- return $engine->result("SELECT id FROM users WHERE username = '" . $engine->secure($k) . "' LIMIT 1");
- }
- final public function getUsername($k)
- {
- global $engine;
- return $this->getInfo($_SESSION['user']['id'], 'username');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement