Advertisement
Guest User

Untitled

a guest
May 6th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.16 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. //SSO Fix by Koala <3
  177. $ssoAuth = 'SSO-' . rand(9, 999) . '/' . substr(sha1(time()) . '/' . rand(9, 9999999) . '/' . rand(9, 9999999) . '/' . rand(9, 9999999), 0, 33);
  178. $this->updateUser($k, 'auth_ticket', $ssoAuth);
  179. unset($ssoAuth);
  180. }
  181.  
  182. final public function updateUser($k, $key, $value)
  183. {
  184. global $engine, $tables;
  185. dbquery("UPDATE " . $tables['table_users'] . " SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  186. $_SESSION['user'][$key] = $engine->secure($value);
  187. }
  188.  
  189. /*-------------------------------Account settings-------------------------------------*/
  190.  
  191. final public function cacheUser($k)
  192. {
  193. global $engine, $tables;
  194. $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");
  195.  
  196. foreach ($userInfo as $key => $value) {
  197. $this->setInfo($key, $value);
  198. }
  199. }
  200.  
  201. final public function setInfo($key, $value)
  202. {
  203. global $engine;
  204. $_SESSION['user'][$key] = $engine->secure($value);
  205. }
  206.  
  207. final public function getReason($value)
  208. {
  209. global $engine;
  210. return $engine->mysqli_result(dbquery("SELECT reason FROM users_bans WHERE value = '" . $value . "' LIMIT 1"));
  211. }
  212.  
  213. final public function login()
  214. {
  215. global $template, $_CONFIG, $core, $users;
  216. if (isset($_POST['login'])) {
  217. $template->form->setData();
  218.  
  219. if (isset($template->form->log_username) && $this->nameTaken($template->form->log_username)) {
  220. if ($this->isBanned($template->form->log_username) == false || $this->isBanned($users->GetIp()) == false) {
  221. if ($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password))) {
  222. $this->turnOn($template->form->log_username);
  223. $this->updateUser($_SESSION['user']['id'], 'ip_current', $users->GetIp());
  224. $template->form->unsetData();
  225. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  226. exit;
  227. } else {
  228. $template->form->error = 'HUPS! Syötit väärän salasanan.';
  229. return;
  230. }
  231. } else {
  232. $template->form->error = 'Et voi kirjautua sisään, koska sinulla on porttikielto<br />';
  233. $template->form->error .= 'Syy: ' . $this->getReason($template->form->log_username);
  234. return;
  235. }
  236. } else {
  237. $template->form->error = 'Kirjoitathan kirjautumis tiedot pääseksesi Swiftiin.';
  238. return;
  239. }
  240. }
  241. }
  242.  
  243. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  244.  
  245. final public function userValidation($username, $password)
  246. {
  247. global $engine, $tables;
  248. if ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1") > 0) {
  249. return true;
  250. }
  251.  
  252. return false;
  253. }
  254.  
  255. final public function loginHK()
  256. {
  257. global $template, $_CONFIG, $core;
  258.  
  259. if (isset($_POST['login'])) {
  260. $template->form->setData();
  261.  
  262. if (isset($template->form->username) && isset($template->form->password)) {
  263. if ($this->nameTaken($template->form->username)) {
  264. if ($this->userValidation($template->form->username, $core->hashed($template->form->password))) {
  265. if (($this->getInfo($_SESSION['user']['id'], 'rank')) >= 4) {
  266. $_SESSION["in_hk"] = true;
  267. header("Location:" . $_CONFIG['hotel']['url'] . "/ase/main");
  268. exit;
  269. } else {
  270. $template->form->error = 'Sinulla ei riitä oikeudet';
  271. return;
  272. }
  273. } else {
  274. $template->form->error = 'Syötit väärän salasanan.';
  275. return;
  276. }
  277. } else {
  278. $template->form->error = 'Hahmoa ei löytynyt.';
  279. return;
  280. }
  281. }
  282.  
  283. $template->form->unsetData();
  284. }
  285. }
  286.  
  287. final public function getInfo($k, $key)
  288. {
  289. global $engine, $tables;
  290. if (!isset($_SESSION['user'][$key])) {
  291. $value = $engine->mysqli_result(dbquery("SELECT $key FROM " . $tables['table_users'] . " WHERE id = '" . filter($k) . "' LIMIT 1"));
  292. if ($value != null) {
  293. $this->setInfo($key, $value);
  294. }
  295. }
  296. return $_SESSION['user'][$key];
  297. }
  298.  
  299. final public function getCurrency($k, $key, $id)
  300. {
  301. global $engine, $tables;
  302. if (!isset($_SESSION['user'][$key])) {
  303. $value = $engine->mysqli_result(dbquery("SELECT amount FROM users_currency WHERE user_id = '" . filter($k) . "' AND type='" . filter($id) . "' LIMIT 1"));
  304. if ($value != null) {
  305. $this->setInfo($key, $value);
  306. }
  307. }
  308. return $_SESSION['user'][$key];
  309. }
  310.  
  311. final public function getOnlineCount()
  312. {
  313. global $engine, $tables;
  314. return $engine->mysqli_result(dbquery("SELECT COUNT(*) as online FROM users WHERE online = '1'"));
  315. }
  316.  
  317. /*-------------------------------Handling user information-------------------------------------*/
  318.  
  319. final public function help()
  320. {
  321. global $template, $_CONFIG;
  322. $template->form->setData();
  323.  
  324. if (isset($template->form->help)) {
  325. $to = $_CONFIG['hotel']['email'];
  326. $subject = "Ajuda de usuário Hebbust- " . $this->getInfo($_SESSION['user']['id'], 'username');
  327. $body = $template->form->question;
  328.  
  329. if (mail($to, $subject, $body)) {
  330. $template->form->error = 'Mensagem enviada com sucesso! Nós vamos responder a você em breve!';
  331. } else {
  332. $template->form->error = 'A entrega da mensagem falhou.';
  333. }
  334. }
  335. }
  336.  
  337. final public function updateAccount()
  338. {
  339. global $template, $core, $engine;
  340.  
  341. if (isset($_POST['account'])) {
  342. if (isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30) {
  343. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  344. } else {
  345. $template->form->error = 'Missão invalida.';
  346. }
  347.  
  348. if (isset($_POST['acc_youtube'])) {
  349. if (strlen($_POST['acc_youtube']) < 50) {
  350. $this->updateUser($_SESSION['user']['id'], 'cms_video', $engine->secure($_POST['acc_youtube']));
  351. } else {
  352. $template->form->error = 'Vídeo muito longo.';
  353. }
  354. }
  355.  
  356. if (isset($_POST['acc_email'])) {
  357. if ($this->validEmail($_POST['acc_email'])) {
  358. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  359. } else {
  360. $template->form->error = 'E-mail invalido.';
  361. return;
  362. }
  363. }
  364.  
  365. if (!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password'])) {
  366. if ($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password']))) {
  367. if (strlen($_POST['acc_new_password']) >= 8) {
  368. $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  369. } else {
  370. $template->form->error = 'Nova senha é muito curta';
  371. return;
  372. }
  373. } else {
  374. $template->form->error = 'Senha atual está errada';
  375. return;
  376. }
  377. }
  378. }
  379. }
  380.  
  381.  
  382. /*-------------------------------Get user ID or Username-------------------------------------*/
  383.  
  384. final public function deleteUser($k)
  385. {
  386. global $engine;
  387. // todo mutli emu
  388. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  389. # $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  390. # $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  391. }
  392.  
  393. final public function getUsername($k)
  394. {
  395. return $this->getInfo($_SESSION['user']['id'], 'username');
  396. }
  397. }
  398. RAW Paste Data
  399.  
  400. <?php
  401.  
  402. namespace Revolution;
  403. if (!defined('IN_INDEX')) {
  404. die('Sorry, you cannot access this file.');
  405. }
  406.  
  407. class users implements iUsers
  408. {
  409.  
  410. /*-------------------------------Authenticate-------------------------------------*/
  411.  
  412. final public function isLogged()
  413. {
  414. return isset($_SESSION['user']['id']);
  415. }
  416.  
  417. /*-------------------------------Checking of submitted data-------------------------------------*/
  418.  
  419. final public function register()
  420. {
  421. global $core, $template, $_CONFIG;
  422.  
  423. if (isset($_POST['register'])) {
  424. unset($template->form->error);
  425.  
  426. $template->form->setData();
  427.  
  428. if ($this->validName($template->form->reg_username)) {
  429. if (!$this->nameTaken($template->form->reg_username)) {
  430. if ($this->validEmail($template->form->reg_email)) {
  431. if (!$this->emailTaken($template->form->reg_email)) {
  432. if (strlen($template->form->reg_password) > 6) {
  433. if ($template->form->reg_password == $template->form->reg_rep_password) {
  434. if ($this->isBanned($_SERVER['REMOTE_ADDR']) == false) {
  435. if (!$this->hasClones($_SERVER['REMOTE_ADDR'])) {
  436. if (!isset($template->form->reg_gender)) {
  437. $template->form->reg_gender = 'M';
  438. }
  439. if (!isset($template->form->reg_figure)) {
  440. $template->form->reg_figure = $_CONFIG['hotel']['figure'];
  441. }
  442.  
  443. $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);
  444.  
  445. $this->turnOn($template->form->reg_username);
  446.  
  447. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  448. exit;
  449. } else {
  450. $template->form->error = 'Desculpe, mas você não pode registrar mais de três vezes!';
  451. }
  452. } else {
  453. $template->form->error = 'Desculpe, parece que você está Banido por IP.<br />';
  454. $template->form->error .= 'Razão: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  455. return;
  456. }
  457. } else {
  458. $template->form->error = 'Senha não corresponde a senha repetida!';
  459. return;
  460. }
  461.  
  462. } else {
  463. $template->form->error = 'A senha deve ter mais de 6 caracteres!';
  464. return;
  465. }
  466. } else {
  467. $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> já está registrado';
  468. return;
  469. }
  470. } else {
  471. $template->form->error = 'E-mail não é válido';
  472. return;
  473. }
  474. } else {
  475. $template->form->error = 'Nome de usuário já está registrado';
  476. return;
  477. }
  478. } else {
  479. $template->form->error = 'Nome de usuário Inválido';
  480. return;
  481. }
  482. }
  483. }
  484.  
  485. final public function validName($username)
  486. {
  487. return strlen($username) <= 25 && ctype_alnum($username);
  488. }
  489.  
  490. final public function nameTaken($username)
  491. {
  492. global $engine, $tables;
  493. return ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE username = '" . $username . "' LIMIT 1") > 0);
  494. }
  495.  
  496. final public function validEmail($email)
  497. {
  498. return preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $email);
  499. }
  500.  
  501. final public function emailTaken($email)
  502. {
  503. global $engine;
  504. return $engine->num_rows("SELECT NULL FROM users WHERE mail = '" . $email . "' LIMIT 1") > 0;
  505. }
  506.  
  507.  
  508. /*-------------------------------Stuff related to bans-------------------------------------*/
  509.  
  510. final public function isBanned($value)
  511. {
  512. global $engine, $tables;
  513. if (($engine->num_rows("SELECT NULL FROM " . $tables['table_bans'] . " WHERE value = '" . $value . "' LIMIT 1") > 0) == 0) {
  514. return false;
  515. }
  516. return true;
  517. }
  518.  
  519. final public function GetIp()
  520. {
  521. $client = @$_SERVER['HTTP_CLIENT_IP'];
  522. $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
  523. $remote = $_SERVER['REMOTE_ADDR'];
  524.  
  525. if (filter_var($client, FILTER_VALIDATE_IP)) {
  526. $ip = $client;
  527. } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
  528. $ip = $forward;
  529. } else {
  530. $ip = $remote;
  531. }
  532. return $ip;
  533. }
  534.  
  535. final public function hasClones($ip)
  536. {
  537. global $engine, $tables;
  538. if ($ip == null) {
  539. $ip = $this->GetIp();
  540. }
  541.  
  542. if ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE ip_register = '" . $ip . "'") == 300) {
  543. return true;
  544. }
  545.  
  546. return false;
  547. }
  548.  
  549. final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender)
  550. {
  551. global $engine, $tables, $users;
  552. $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() . "')");
  553. unset($sessionKey);
  554. }
  555.  
  556. /*-------------------------------Login or Register user-------------------------------------*/
  557.  
  558. final public function turnOn($k)
  559. {
  560. $j = $this->getID($k);
  561. $this->createSSO($j);
  562. $_SESSION['user']['id'] = $j;
  563. $this->cacheUser($j);
  564. unset($j);
  565. }
  566.  
  567. final public function getID($k)
  568. {
  569. global $engine, $tables;
  570. return $engine->mysqli_result(dbquery("SELECT id FROM " . $tables['table_users'] . " WHERE username = '" . $engine->secure($k) . "' LIMIT 1"));
  571. }
  572.  
  573. final public function createSSO($k)
  574. {
  575. $sessionKey = 'SSO-' . rand(9, 999) . '/' . substr(sha1(time()) . '/' . rand(9, 9999999) . '/' . rand(9, 9999999) . '/' . rand(9, 9999999), 0, 33);
  576.  
  577. $this->updateUser($k, 'auth_ticket', $sessionKey);
  578.  
  579. unset($sessionKey);
  580. }
  581.  
  582. final public function updateUser($k, $key, $value)
  583. {
  584. global $engine, $tables;
  585. dbquery("UPDATE " . $tables['table_users'] . " SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  586. $_SESSION['user'][$key] = $engine->secure($value);
  587. }
  588.  
  589. /*-------------------------------Account settings-------------------------------------*/
  590.  
  591. final public function cacheUser($k)
  592. {
  593. global $engine, $tables;
  594. $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");
  595.  
  596. foreach ($userInfo as $key => $value) {
  597. $this->setInfo($key, $value);
  598. }
  599. }
  600.  
  601. final public function setInfo($key, $value)
  602. {
  603. global $engine;
  604. $_SESSION['user'][$key] = $engine->secure($value);
  605. }
  606.  
  607. final public function getReason($value)
  608. {
  609. global $engine;
  610. return $engine->mysqli_result(dbquery("SELECT reason FROM users_bans WHERE value = '" . $value . "' LIMIT 1"));
  611. }
  612.  
  613. final public function login()
  614. {
  615. global $template, $_CONFIG, $core, $users;
  616. if (isset($_POST['login'])) {
  617. $template->form->setData();
  618.  
  619. if (isset($template->form->log_username) && $this->nameTaken($template->form->log_username)) {
  620. if ($this->isBanned($template->form->log_username) == false || $this->isBanned($users->GetIp()) == false) {
  621. if ($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password))) {
  622. $this->turnOn($template->form->log_username);
  623. $this->updateUser($_SESSION['user']['id'], 'ip_current', $users->GetIp());
  624. $template->form->unsetData();
  625. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  626. exit;
  627. } else {
  628. $template->form->error = 'HUPS! Syötit väärän salasanan.';
  629. return;
  630. }
  631. } else {
  632. $template->form->error = 'Et voi kirjautua sisään, koska sinulla on porttikielto<br />';
  633. $template->form->error .= 'Syy: ' . $this->getReason($template->form->log_username);
  634. return;
  635. }
  636. } else {
  637. $template->form->error = 'Kirjoitathan kirjautumis tiedot pääseksesi Swiftiin.';
  638. return;
  639. }
  640. }
  641. }
  642.  
  643. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  644.  
  645. final public function userValidation($username, $password)
  646. {
  647. global $engine, $tables;
  648. if ($engine->num_rows("SELECT NULL FROM " . $tables['table_users'] . " WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1") > 0) {
  649. return true;
  650. }
  651.  
  652. return false;
  653. }
  654.  
  655. final public function loginHK()
  656. {
  657. global $template, $_CONFIG, $core;
  658.  
  659. if (isset($_POST['login'])) {
  660. $template->form->setData();
  661.  
  662. if (isset($template->form->username) && isset($template->form->password)) {
  663. if ($this->nameTaken($template->form->username)) {
  664. if ($this->userValidation($template->form->username, $core->hashed($template->form->password))) {
  665. if (($this->getInfo($_SESSION['user']['id'], 'rank')) >= 4) {
  666. $_SESSION["in_hk"] = true;
  667. header("Location:" . $_CONFIG['hotel']['url'] . "/ase/main");
  668. exit;
  669. } else {
  670. $template->form->error = 'Sinulla ei riitä oikeudet';
  671. return;
  672. }
  673. } else {
  674. $template->form->error = 'Syötit väärän salasanan.';
  675. return;
  676. }
  677. } else {
  678. $template->form->error = 'Hahmoa ei löytynyt.';
  679. return;
  680. }
  681. }
  682.  
  683. $template->form->unsetData();
  684. }
  685. }
  686.  
  687. final public function getInfo($k, $key)
  688. {
  689. global $engine, $tables;
  690. if (!isset($_SESSION['user'][$key])) {
  691. $value = $engine->mysqli_result(dbquery("SELECT $key FROM " . $tables['table_users'] . " WHERE id = '" . filter($k) . "' LIMIT 1"));
  692. if ($value != null) {
  693. $this->setInfo($key, $value);
  694. }
  695. }
  696. return $_SESSION['user'][$key];
  697. }
  698.  
  699. final public function getCurrency($k, $key, $id)
  700. {
  701. global $engine, $tables;
  702. if (!isset($_SESSION['user'][$key])) {
  703. $value = $engine->mysqli_result(dbquery("SELECT amount FROM users_currency WHERE user_id = '" . filter($k) . "' AND type='" . filter($id) . "' LIMIT 1"));
  704. if ($value != null) {
  705. $this->setInfo($key, $value);
  706. }
  707. }
  708. return $_SESSION['user'][$key];
  709. }
  710.  
  711. final public function getOnlineCount()
  712. {
  713. global $engine, $tables;
  714. return $engine->mysqli_result(dbquery("SELECT COUNT(*) as online FROM users WHERE online = '1'"));
  715. }
  716.  
  717. /*-------------------------------Handling user information-------------------------------------*/
  718.  
  719. final public function help()
  720. {
  721. global $template, $_CONFIG;
  722. $template->form->setData();
  723.  
  724. if (isset($template->form->help)) {
  725. $to = $_CONFIG['hotel']['email'];
  726. $subject = "Ajuda de usuário Hebbust- " . $this->getInfo($_SESSION['user']['id'], 'username');
  727. $body = $template->form->question;
  728.  
  729. if (mail($to, $subject, $body)) {
  730. $template->form->error = 'Mensagem enviada com sucesso! Nós vamos responder a você em breve!';
  731. } else {
  732. $template->form->error = 'A entrega da mensagem falhou.';
  733. }
  734. }
  735. }
  736.  
  737. final public function updateAccount()
  738. {
  739. global $template, $core, $engine;
  740.  
  741. if (isset($_POST['account'])) {
  742. if (isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30) {
  743. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  744. } else {
  745. $template->form->error = 'Missão invalida.';
  746. }
  747.  
  748. if (isset($_POST['acc_youtube'])) {
  749. if (strlen($_POST['acc_youtube']) < 50) {
  750. $this->updateUser($_SESSION['user']['id'], 'cms_video', $engine->secure($_POST['acc_youtube']));
  751. } else {
  752. $template->form->error = 'Vídeo muito longo.';
  753. }
  754. }
  755.  
  756. if (isset($_POST['acc_email'])) {
  757. if ($this->validEmail($_POST['acc_email'])) {
  758. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  759. } else {
  760. $template->form->error = 'E-mail invalido.';
  761. return;
  762. }
  763. }
  764.  
  765. if (!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password'])) {
  766. if ($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password']))) {
  767. if (strlen($_POST['acc_new_password']) >= 8) {
  768. $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  769. } else {
  770. $template->form->error = 'Nova senha é muito curta';
  771. return;
  772. }
  773. } else {
  774. $template->form->error = 'Senha atual está errada';
  775. return;
  776. }
  777. }
  778. }
  779. }
  780.  
  781.  
  782. /*-------------------------------Get user ID or Username-------------------------------------*/
  783.  
  784. final public function deleteUser($k)
  785. {
  786. global $engine;
  787. // todo mutli emu
  788. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  789. # $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  790. # $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  791. }
  792.  
  793. final public function getUsername($k)
  794. {
  795. return $this->getInfo($_SESSION['user']['id'], 'username');
  796. }
  797. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement