Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.27 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 && ctype_alnum($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'] . "'") == 2)
  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 must only have 4 numbers';
  146. return;
  147. }
  148. }
  149. if($this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  150. {
  151. if(!$this->hasClones($_SERVER['REMOTE_ADDR']))
  152. {
  153.  
  154. if(!isset($template->form->reg_gender)) { $template->form->reg_gender = 'M'; }
  155. if(!isset($template->form->reg_figure)) { $template->form->reg_figure = $_CONFIG['hotel']['figure']; }
  156.  
  157. $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));
  158.  
  159. $this->turnOn($template->form->reg_username);
  160.  
  161. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  162. exit;
  163. }
  164. else
  165. {
  166. $template->form->error = 'Sorry, but you cannot register twice';
  167. }
  168. }
  169. else
  170. {
  171. $template->form->error = 'Sorry, it appears you are IP banned.<br />';
  172. $template->form->error .= 'Reason: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  173. return;
  174. }
  175. }
  176. else
  177. {
  178. $template->form->error = 'Password does not match repeated password';
  179. return;
  180. }
  181.  
  182. }
  183. else
  184. {
  185. $template->form->error = 'Password must have more than 6 characters';
  186. return;
  187. }
  188. }
  189. else
  190. {
  191. $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> is already registered';
  192. return;
  193. }
  194. }
  195. else
  196. {
  197. $template->form->error = 'Email is not valid';
  198. return;
  199. }
  200. }
  201. else
  202. {
  203. $template->form->error = 'Username is already registered';
  204. return;
  205. }
  206. }
  207. else
  208. {
  209. $template->form->error = 'Username is invalid';
  210. return;
  211. }
  212. }
  213. }
  214.  
  215. final public function login()
  216. {
  217. global $template, $_CONFIG, $core;
  218.  
  219. if(isset($_POST['login']))
  220. {
  221. $template->form->setData();
  222. unset($template->form->error);
  223.  
  224. if($this->nameTaken($template->form->log_username))
  225. {
  226. if($this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  227. {
  228. if($this->isBanned($template->form->log_username) == 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 onjuist.';
  241. return;
  242. }
  243. }
  244. else
  245. {
  246. $template->form->error = 'Sorry, Maar je bent verbannen van Horba.<br />';
  247. $template->form->error .= 'Reden: ' . $this->getReason($template->form->log_username);
  248. return;
  249. }
  250. }
  251. else
  252. {
  253. $template->form->error = 'Sorry, Maar dit IP is verbannen van Horba. <br />';
  254. $template->form->error .= 'Reason: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  255. return;
  256. }
  257. }
  258. else
  259. {
  260. $template->form->error = 'Gebruikersnaam bestaat niet.';
  261. return;
  262. }
  263. }
  264. }
  265.  
  266. final public function loginHK()
  267. {
  268. global $template, $_CONFIG, $core;
  269.  
  270. if(isset($_POST['login']))
  271. {
  272. $template->form->setData();
  273. unset($template->form->error);
  274.  
  275. if(isset($template->form->username) && isset($template->form->password))
  276. {
  277. if($this->nameTaken($template->form->username))
  278. {
  279. if($this->userValidation($template->form->username, $core->hashed($template->form->password)))
  280. {
  281. if(($this->getInfo($_SESSION['user']['id'], 'rank')) >= 4)
  282. {
  283. $_SESSION["in_hk"] = true;
  284. header("Location:".$_CONFIG['hotel']['url']."/ase/index.php?url=dash");
  285. exit;
  286. }
  287. else
  288. {
  289. $template->form->error = 'Incorrect access level.';
  290. return;
  291. }
  292. }
  293. else
  294. {
  295. $template->form->error = 'Incorrect password.';
  296. return;
  297. }
  298. }
  299. else
  300. {
  301. $template->form->error = 'User does not exist.';
  302. return;
  303. }
  304. }
  305.  
  306. $template->form->unsetData();
  307. }
  308. }
  309.  
  310. final public function help()
  311. {
  312. global $template, $_CONFIG;
  313. $template->form->setData();
  314.  
  315. if(isset($template->form->help))
  316. {
  317. $to = $_CONFIG['hotel']['email'];
  318. $subject = "Help from RevCMS user - " . $this->getInfo($_SESSION['user']['id'], 'username');
  319. $body = $template->form->question;
  320.  
  321. if (mail($to, $subject, $body))
  322. {
  323. $template->form->error = 'Message successfully sent! We will answer you shortly!';
  324. }
  325. else
  326. {
  327. $template->form->error = 'Message delivery failed.';
  328. }
  329. }
  330. }
  331.  
  332. /*-------------------------------Account settings-------------------------------------*/
  333.  
  334. final public function updateAccount()
  335. {
  336. global $template, $_CONFIG, $core, $engine;
  337.  
  338. if(isset($_POST['account']))
  339. {
  340.  
  341. if(isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30 && $_POST['acc_motto'] != $this->getInfo($_SESSION['user']['id'], 'motto'))
  342. {
  343. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  344. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  345. exit;
  346. }
  347. else
  348. {
  349. $template->form->error = 'Motto is invalid.';
  350. }
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. if(isset($_POST['color2']) && strlen($_POST['color2']) )
  360. {
  361. $this->updateUser($_SESSION['user']['id'], 'color5', $engine->secure($_POST['color5']));
  362. $this->updateUser($_SESSION['user']['id'], 'color4', $engine->secure($_POST['color4']));
  363. $this->updateUser($_SESSION['user']['id'], 'color3', $engine->secure($_POST['color3']));
  364. $this->updateUser($_SESSION['user']['id'], 'color2', $engine->secure($_POST['color2']));
  365. $this->updateUser($_SESSION['user']['id'], 'color', $engine->secure($_POST['color']));
  366. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  367. exit;
  368. }
  369. else
  370. {
  371. $template->form->error = 'Kleur klopt niet';
  372. }
  373.  
  374.  
  375. if(isset($_POST['color']) && strlen($_POST['color']) )
  376. {
  377. $this->updateUser($_SESSION['user']['id'], 'color', $engine->secure($_POST['color']));
  378. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  379. exit;
  380. }
  381. else
  382. {
  383. $template->form->error = 'Kleur klopt niet';
  384.  
  385. }
  386.  
  387. if(isset($_POST['acc_email']) && $_POST['acc_email'] != $this->getInfo($_SESSION['user']['id'], 'mail'))
  388. {
  389. if($this->validEmail($_POST['acc_email']))
  390. {
  391. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  392. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  393. exit;
  394. }
  395. else
  396. {
  397. $template->form->error = 'Email is not valid';
  398. return;
  399. }
  400. }
  401.  
  402. if(!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password']))
  403. {
  404. if($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password'])))
  405. {
  406. if(strlen($_POST['acc_new_password']) >= 8)
  407. {
  408. $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  409. header('Location: '.$_CONFIG['hotel']['url'].'/me');
  410. exit;
  411. }
  412. else
  413. {
  414. $template->form->error = 'New password is too short';
  415. return;
  416. }
  417. }
  418. else
  419. {
  420. $template->form->error = 'Current password is wrong';
  421. return;
  422. }
  423. }
  424. }
  425. }
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435. /*-------------------------------Account settings-------------------------------------*/
  436.  
  437. final public function color()
  438. {
  439. global $template, $_CONFIG, $core, $engine;
  440.  
  441. if(isset($_POST['color']))
  442. {
  443.  
  444. if(isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30 && $_POST['acc_motto'] != $this->getInfo($_SESSION['user']['id'], 'motto'))
  445. {
  446. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  447. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  448. exit;
  449. }
  450. else
  451. {
  452. $template->form->error = 'Motto is invalid.';
  453. }
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463. }
  464. }
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482. final public function turnOn($k)
  483. {
  484. $j = $this->getID($k);
  485. $this->createSSO($j);
  486. $_SESSION['user']['id'] = $j;
  487. $this->cacheUser($j);
  488. unset($j);
  489. }
  490.  
  491.  
  492. /*-------------------------------Create SSO auth_ticket-------------------------------------*/
  493.  
  494. final public function createSSO($k)
  495. {
  496. $sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  497.  
  498. $this->updateUser($k, 'auth_ticket', $sessionKey);
  499.  
  500. unset($sessionKey);
  501. }
  502.  
  503. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  504.  
  505. final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender, $seckey)
  506. {
  507.  
  508. if($_POST['ref']){
  509. $ref = $_POST['ref'];
  510. $this->ref($ref);
  511. }else{
  512.  
  513. global $engine;
  514. $sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  515. $engine->query("INSERT INTO users (username, password, mail, motto, credits, pixels, 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 . "')");
  516. $user_id = $this->getID($username);
  517. $engine->query("INSERT INTO user_info (user_id, bans, cautions, reg_timestamp, login_timestamp, cfhs, cfhs_abusive) VALUES ('". $user_id ."', '0', '0', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '0')");
  518. unset($sessionKey);
  519. }
  520. }
  521.  
  522. final public function deleteUser($k)
  523. {
  524. global $engine;
  525. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  526. $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  527. $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  528. }
  529.  
  530. final public function updateUser($k, $key, $value)
  531. {
  532. global $engine;
  533. $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  534. $_SESSION['user'][$key] = $engine->secure($value);
  535. }
  536.  
  537. /*-------------------------------Handling user information-------------------------------------*/
  538.  
  539. final public function cacheUser($k)
  540. {
  541. global $engine;
  542. $userInfo = $engine->fetch_assoc("SELECT username, rank, motto, mail, credits, activity_points, look, auth_ticket, ip_last FROM users WHERE id = '" . $k . "' LIMIT 1");
  543.  
  544. foreach($userInfo as $key => $value)
  545. {
  546. $this->setInfo($key, $value);
  547. }
  548. }
  549.  
  550. final public function setInfo($key, $value)
  551. {
  552. global $engine;
  553. $_SESSION['user'][$key] = $engine->secure($value);
  554. }
  555.  
  556. final public function getInfo($k, $key)
  557. {
  558. global $engine;
  559. if(!isset($_SESSION['user'][$key]))
  560. {
  561. $value = $engine->result("SELECT $key FROM users WHERE id = '" . $engine->secure($k) . "' LIMIT 1");
  562. if($value != null)
  563. {
  564. $this->setInfo($key, $value);
  565. }
  566. }
  567.  
  568. return $_SESSION['user'][$key];
  569. }
  570.  
  571.  
  572.  
  573. /*-------------------------------Get user ID or Username-------------------------------------*/
  574.  
  575. final public function getID($k)
  576. {
  577. global $engine;
  578. return $engine->result("SELECT id FROM users WHERE username = '" . $engine->secure($k) . "' LIMIT 1");
  579. }
  580.  
  581. final public function getUsername($k)
  582. {
  583. global $engine;
  584. return $this->getInfo($_SESSION['user']['id'], 'username');
  585. }
  586.  
  587. }
  588. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement