Advertisement
Guest User

Untitled

a guest
May 6th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.02 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Revolution;
  4. if (!defined('IN_INDEX')) {
  5. die('Sorry, you cannot access this file.');
  6. }
  7.  
  8. class users implements iUsers
  9. {
  10.  
  11. /*-------------------------------Authenticate-------------------------------------*/
  12.  
  13. final public function isLogged()
  14. {
  15. return isset($_SESSION['user']['id']);
  16. }
  17.  
  18. /*-------------------------------Checking of submitted data-------------------------------------*/
  19.  
  20. final public function register()
  21. {
  22. global $core, $template, $_CONFIG;
  23.  
  24. if (isset($_POST['register'])) {
  25. unset($template->form->error);
  26.  
  27. $template->form->setData();
  28.  
  29. if ($this->validName($template->form->reg_username)) {
  30. if (!$this->nameTaken($template->form->reg_username)) {
  31. if ($this->validEmail($template->form->reg_email)) {
  32. if (!$this->emailTaken($template->form->reg_email)) {
  33. if (strlen($template->form->reg_password) > 6) {
  34. if ($template->form->reg_password == $template->form->reg_rep_password) {
  35. if ($this->isBanned($_SERVER['REMOTE_ADDR']) == false) {
  36. if (!$this->hasClones($_SERVER['REMOTE_ADDR'])) {
  37. if (!isset($template->form->reg_gender)) {
  38. $template->form->reg_gender = 'M';
  39. }
  40. if (!isset($template->form->reg_figure)) {
  41. $template->form->reg_figure = $_CONFIG['hotel']['figure'];
  42. }
  43.  
  44. $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);
  45.  
  46. $this->turnOn($template->form->reg_username);
  47.  
  48. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  49. exit;
  50. } else {
  51. $template->form->error = 'Desculpe, mas você não pode registrar mais de três vezes!';
  52. }
  53. } else {
  54. $template->form->error = 'Desculpe, parece que você está Banido por IP.<br />';
  55. $template->form->error .= 'Razão: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  56. return;
  57. }
  58. } else {
  59. $template->form->error = 'Senha não corresponde a senha repetida!';
  60. return;
  61. }
  62.  
  63. } else {
  64. $template->form->error = 'A senha deve ter mais de 6 caracteres!';
  65. return;
  66. }
  67. } else {
  68. $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> já está registrado';
  69. return;
  70. }
  71. } else {
  72. $template->form->error = 'E-mail não é válido';
  73. return;
  74. }
  75. } else {
  76. $template->form->error = 'Nome de usuário já está registrado';
  77. return;
  78. }
  79. } else {
  80. $template->form->error = 'Nome de usuário Inválido';
  81. return;
  82. }
  83. }
  84. }
  85.  
  86. final public function validName($username)
  87. {
  88. return strlen($username) <= 25 && ctype_alnum($username);
  89. }
  90.  
  91. final public function nameTaken($username)
  92. {
  93. global $engine, $tables;
  94. return ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE username = '" . $username . "' LIMIT 1") > 0);
  95. }
  96.  
  97. final public function validEmail($email)
  98. {
  99. return preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $email);
  100. }
  101.  
  102. final public function emailTaken($email)
  103. {
  104. global $engine;
  105. return $engine->num_rows("SELECT NULL FROM users WHERE mail = '" . $email . "' LIMIT 1") > 0;
  106. }
  107.  
  108.  
  109. /*-------------------------------Stuff related to bans-------------------------------------*/
  110.  
  111. final public function isBanned($value)
  112. {
  113. global $engine, $tables;
  114. if (($engine->num_rows("SELECT NULL FROM " . $tables['table_bans'] . " WHERE value = '" . $value . "' LIMIT 1") > 0) == 0) {
  115. return false;
  116. }
  117. return true;
  118. }
  119.  
  120. final public function GetIp()
  121. {
  122. $client = @$_SERVER['HTTP_CLIENT_IP'];
  123. $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
  124. $remote = $_SERVER['REMOTE_ADDR'];
  125.  
  126. if (filter_var($client, FILTER_VALIDATE_IP)) {
  127. $ip = $client;
  128. } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
  129. $ip = $forward;
  130. } else {
  131. $ip = $remote;
  132. }
  133. return $ip;
  134. }
  135.  
  136. final public function hasClones($ip)
  137. {
  138. global $engine, $tables;
  139. if ($ip == null) {
  140. $ip = $this->GetIp();
  141. }
  142.  
  143. if ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE ip_register = '" . $ip . "'") == 300) {
  144. return true;
  145. }
  146.  
  147. return false;
  148. }
  149.  
  150. final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender)
  151. {
  152. global $engine, $tables, $users;
  153. $engine->query("INSERT INTO users (username, password, mail, motto, credits, " . $tables['rank_pixels'] . ", rank, look, gender, ip_current, ip_register, account_created, last_online) VALUES('" . $username . "', '" . $password . "', '" . $email . "', '" . $motto . "', '" . $credits . "', '" . $pixels . "', '" . $rank . "', '" . $figure . "', '" . $gender . "', '" . $users->GetIp() . "', '" . $users->GetIp() . "', '" . time() . "', '" . time() . "')");
  154. unset($sessionKey);
  155. }
  156.  
  157. /*-------------------------------Login or Register user-------------------------------------*/
  158.  
  159. final public function turnOn($k)
  160. {
  161. $j = $this->getID($k);
  162. $this->createSSO($j);
  163. $_SESSION['user']['id'] = $j;
  164. $this->cacheUser($j);
  165. unset($j);
  166. }
  167.  
  168. final public function getID($k)
  169. {
  170. global $engine, $tables;
  171. return $engine->mysqli_result(dbquery("SELECT id FROM " . $tables['table_users'] . " WHERE username = '" . $engine->secure($k) . "' LIMIT 1"));
  172. }
  173.  
  174. final public function createSSO($k)
  175. {
  176. $sessionKey = 'SSO-' . rand(9, 999) . '/' . substr(sha1(time()) . '/' . rand(9, 9999999) . '/' . rand(9, 9999999) . '/' . rand(9, 9999999), 0, 33);
  177. $this->updateUser($k, 'auth_ticket', $sessionKey);
  178. unset($sessionKey);
  179. }
  180.  
  181. final public function updateUser($k, $key, $value)
  182. {
  183. global $engine, $tables;
  184. dbquery("UPDATE " . $tables['table_users'] . " SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  185. $_SESSION['user'][$key] = $engine->secure($value);
  186. }
  187.  
  188. /*-------------------------------Account settings-------------------------------------*/
  189.  
  190. final public function cacheUser($k)
  191. {
  192. global $engine, $tables;
  193. $userInfo = $engine->fetch_assoc("SELECT " . $tables['users_row'] . "," . $tables['rank_credits'] . "," . $tables['rank_pixels'] . "," . $tables['rank_diamonds'] . " FROM " . $tables['table_users'] . " WHERE id = '" . $k . "' LIMIT 1");
  194.  
  195. foreach ($userInfo as $key => $value) {
  196. $this->setInfo($key, $value);
  197. }
  198. }
  199.  
  200. final public function setInfo($key, $value)
  201. {
  202. global $engine;
  203. $_SESSION['user'][$key] = $engine->secure($value);
  204. }
  205.  
  206. final public function getReason($value)
  207. {
  208. global $engine;
  209. return $engine->mysqli_result(dbquery("SELECT reason FROM users_bans WHERE value = '" . $value . "' LIMIT 1"));
  210. }
  211.  
  212. final public function login()
  213. {
  214. global $template, $_CONFIG, $core, $users;
  215. if (isset($_POST['login'])) {
  216. $template->form->setData();
  217.  
  218. if (isset($template->form->log_username) && $this->nameTaken($template->form->log_username)) {
  219. if ($this->isBanned($template->form->log_username) == false || $this->isBanned($users->GetIp()) == false) {
  220. if ($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password))) {
  221. $this->turnOn($template->form->log_username);
  222. $this->updateUser($_SESSION['user']['id'], 'ip_current', $users->GetIp());
  223. $template->form->unsetData();
  224. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  225. exit;
  226. } else {
  227. $template->form->error = 'HUPS! Syötit väärän salasanan.';
  228. return;
  229. }
  230. } else {
  231. $template->form->error = 'Et voi kirjautua sisään, koska sinulla on porttikielto<br />';
  232. $template->form->error .= 'Syy: ' . $this->getReason($template->form->log_username);
  233. return;
  234. }
  235. } else {
  236. $template->form->error = 'Kirjoitathan kirjautumis tiedot pääseksesi Swiftiin.';
  237. return;
  238. }
  239. }
  240. }
  241.  
  242. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  243.  
  244. final public function userValidation($username, $password)
  245. {
  246. global $engine, $tables;
  247. if ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1") > 0) {
  248. return true;
  249. }
  250.  
  251. return false;
  252. }
  253.  
  254. final public function loginHK()
  255. {
  256. global $template, $_CONFIG, $core;
  257.  
  258. if (isset($_POST['login'])) {
  259. $template->form->setData();
  260.  
  261. if (isset($template->form->username) && isset($template->form->password)) {
  262. if ($this->nameTaken($template->form->username)) {
  263. if ($this->userValidation($template->form->username, $core->hashed($template->form->password))) {
  264. if (($this->getInfo($_SESSION['user']['id'], 'rank')) >= 4) {
  265. $_SESSION["in_hk"] = true;
  266. header("Location:" . $_CONFIG['hotel']['url'] . "/ase/main");
  267. exit;
  268. } else {
  269. $template->form->error = 'Sinulla ei riitä oikeudet';
  270. return;
  271. }
  272. } else {
  273. $template->form->error = 'Syötit väärän salasanan.';
  274. return;
  275. }
  276. } else {
  277. $template->form->error = 'Hahmoa ei löytynyt.';
  278. return;
  279. }
  280. }
  281.  
  282. $template->form->unsetData();
  283. }
  284. }
  285.  
  286. final public function getInfo($k, $key)
  287. {
  288. global $engine, $tables;
  289. if (!isset($_SESSION['user'][$key])) {
  290. $value = $engine->mysqli_result(dbquery("SELECT $key FROM " . $tables['table_users'] . " WHERE id = '" . filter($k) . "' LIMIT 1"));
  291. if ($value != null) {
  292. $this->setInfo($key, $value);
  293. }
  294. }
  295. return $_SESSION['user'][$key];
  296. }
  297.  
  298. final public function getCurrency($k, $key, $id)
  299. {
  300. global $engine, $tables;
  301. if (!isset($_SESSION['user'][$key])) {
  302. $value = $engine->mysqli_result(dbquery("SELECT amount FROM users_currency WHERE user_id = '" . filter($k) . "' AND type='" . filter($id) . "' LIMIT 1"));
  303. if ($value != null) {
  304. $this->setInfo($key, $value);
  305. }
  306. }
  307. return $_SESSION['user'][$key];
  308. }
  309.  
  310. final public function getOnlineCount()
  311. {
  312. global $engine, $tables;
  313. return $engine->mysqli_result(dbquery("SELECT COUNT(*) as online FROM users WHERE online = '1'"));
  314. }
  315.  
  316. /*-------------------------------Handling user information-------------------------------------*/
  317.  
  318. final public function help()
  319. {
  320. global $template, $_CONFIG;
  321. $template->form->setData();
  322.  
  323. if (isset($template->form->help)) {
  324. $to = $_CONFIG['hotel']['email'];
  325. $subject = "Ajuda de usuário Hebbust- " . $this->getInfo($_SESSION['user']['id'], 'username');
  326. $body = $template->form->question;
  327.  
  328. if (mail($to, $subject, $body)) {
  329. $template->form->error = 'Mensagem enviada com sucesso! Nós vamos responder a você em breve!';
  330. } else {
  331. $template->form->error = 'A entrega da mensagem falhou.';
  332. }
  333. }
  334. }
  335.  
  336. final public function updateAccount()
  337. {
  338. global $template, $core, $engine;
  339.  
  340. if (isset($_POST['account'])) {
  341. if (isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30) {
  342. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  343. } else {
  344. $template->form->error = 'Missão invalida.';
  345. }
  346.  
  347. if (isset($_POST['acc_youtube'])) {
  348. if (strlen($_POST['acc_youtube']) < 50) {
  349. $this->updateUser($_SESSION['user']['id'], 'cms_video', $engine->secure($_POST['acc_youtube']));
  350. } else {
  351. $template->form->error = 'Vídeo muito longo.';
  352. }
  353. }
  354.  
  355. if (isset($_POST['acc_email'])) {
  356. if ($this->validEmail($_POST['acc_email'])) {
  357. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  358. } else {
  359. $template->form->error = 'E-mail invalido.';
  360. return;
  361. }
  362. }
  363.  
  364. if (!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password'])) {
  365. if ($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password']))) {
  366. if (strlen($_POST['acc_new_password']) >= 8) {
  367. $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  368. } else {
  369. $template->form->error = 'Nova senha é muito curta';
  370. return;
  371. }
  372. } else {
  373. $template->form->error = 'Senha atual está errada';
  374. return;
  375. }
  376. }
  377. }
  378. }
  379.  
  380.  
  381. /*-------------------------------Get user ID or Username-------------------------------------*/
  382.  
  383. final public function deleteUser($k)
  384. {
  385. global $engine;
  386. // todo mutli emu
  387. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  388. # $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  389. # $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  390. }
  391.  
  392. final public function getUsername($k)
  393. {
  394. return $this->getInfo($_SESSION['user']['id'], 'username');
  395. }
  396. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement