Advertisement
Guest User

Untitled

a guest
Apr 16th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.71 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. if($engine->num_rows("SELECT * FROM bans WHERE value = '" . $value . "' LIMIT 1") > 0)
  88. {
  89. return true;
  90. }
  91.  
  92. return false;
  93. }
  94.  
  95. final public function getReason($value)
  96. {
  97. global $engine;
  98. return $engine->result("SELECT reason FROM bans WHERE value = '" . $value . "' LIMIT 1");
  99. }
  100.  
  101. final public function hasClones($ip)
  102. {
  103. global $engine;
  104. if($engine->num_rows("SELECT * FROM users WHERE ip_reg = '" . $_SERVER['REMOTE_ADDR'] . "'") == 3)
  105. {
  106. return true;
  107. }
  108.  
  109. return false;
  110. }
  111.  
  112. /*-------------------------------Login or Register user-------------------------------------*/
  113.  
  114. final public function register()
  115. {
  116. global $core, $template, $_CONFIG;
  117.  
  118. if(isset($_POST['register']))
  119. {
  120. unset($template->form->error);
  121.  
  122. $template->form->setData();
  123.  
  124. if($this->validName($template->form->reg_username))
  125. {
  126. if(!$this->nameTaken($template->form->reg_username))
  127. {
  128. if($this->validEmail($template->form->reg_email))
  129. {
  130. if(!$this->emailTaken($template->form->reg_email))
  131. {
  132. if(strlen($template->form->reg_password) > 6)
  133. {
  134. if($template->form->reg_password == $template->form->reg_rep_password)
  135. {
  136. if(isset($template->form->reg_seckey))
  137. {
  138. if($this->validSecKey($template->form->reg_seckey))
  139. {
  140. //Continue
  141. }
  142. else
  143. {
  144. $template->form->error = 'Secret key must only have 4 numbers';
  145. return;
  146. }
  147. }
  148. if($this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  149. {
  150. if(!$this->hasClones($_SERVER['REMOTE_ADDR']))
  151. {
  152. if(!isset($template->form->reg_gender)) { $template->form->reg_gender = 'M'; }
  153. if(!isset($template->form->reg_figure)) { $template->form->reg_figure = $_CONFIG['hotel']['figure']; }
  154.  
  155. $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));
  156.  
  157. $user_id = mysql_insert_id();
  158. mysql_query("INSERT INTO user_stats (id, RoomVisits, OnlineTime, Respect, RespectGiven, GiftsGiven, GiftsReceived, DailyRespectPoints, DailyPetRespectPoints) VALUES ('".$user_id."', 0, 0, 0, 0, 0, 0, 3, 3)");
  159.  
  160. mysql_query("INSERT INTO user_info (user_id, bans, cautions, reg_timestamp, login_timestamp, cfhs, cfhs_abusive) VALUES ('".$user_id."', '0', '0', UNIX_TIMESTAMP(), '0', '0', '0')");
  161.  
  162. $this->turnOn($template->form->reg_username);
  163.  
  164. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  165. exit;
  166. }
  167. else
  168. {
  169. $template->form->error = 'Sorry, but you cannot register twice';
  170. }
  171. }
  172. else
  173. {
  174. $template->form->error = 'Sorry, it appears you are IP banned.<br />';
  175. $template->form->error .= 'Reason: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  176. return;
  177. }
  178. }
  179. else
  180. {
  181. $template->form->error = 'Password does not match repeated password';
  182. return;
  183. }
  184.  
  185. }
  186. else
  187. {
  188. $template->form->error = 'Password must have more than 6 characters';
  189. return;
  190. }
  191. }
  192. else
  193. {
  194. $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> is already registered';
  195. return;
  196. }
  197. }
  198. else
  199. {
  200. $template->form->error = 'Email is not valid';
  201. return;
  202. }
  203. }
  204. else
  205. {
  206. $template->form->error = 'Username is already registered';
  207. return;
  208. }
  209. }
  210. else
  211. {
  212. $template->form->error = 'Username is invalid';
  213. return;
  214. }
  215. }
  216. }
  217.  
  218. final public function login()
  219. {
  220. global $template, $_CONFIG, $core;
  221.  
  222. if(isset($_POST['login']))
  223. {
  224. $template->form->setData();
  225. unset($template->form->error);
  226.  
  227. if($this->nameTaken($template->form->log_username))
  228. {
  229. if($this->isBanned($template->form->log_username) == false || $this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  230. {
  231. if($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password)))
  232. {
  233. $this->turnOn($template->form->log_username);
  234. $this->updateUser($_SESSION['user']['id'], 'ip_last', $_SERVER['REMOTE_ADDR']);
  235. $template->form->unsetData();
  236. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  237. exit;
  238. }
  239. else
  240. {
  241. $template->form->error = 'Password incorrect!';
  242. return;
  243. }
  244. }
  245. else
  246. {
  247. $template->form->error = 'You are banned!<br />';
  248. $template->form->error .= 'Reason: ' . $this->getReason($template->form->log_username);
  249. return;
  250. }
  251. }
  252. else
  253. {
  254. $template->form->error = 'Username does not exist!';
  255. return;
  256. }
  257. }
  258. }
  259.  
  260. final public function loginHK()
  261. {
  262. global $template, $_CONFIG, $core;
  263.  
  264. if(isset($_POST['login']))
  265. {
  266. $template->form->setData();
  267. unset($template->form->error);
  268.  
  269. if(isset($template->form->username) && isset($template->form->password))
  270. {
  271. if($this->nameTaken($template->form->username))
  272. {
  273. if($this->userValidation($template->form->username, $core->hashed($template->form->password)))
  274. {
  275. if(($this->getInfo($_SESSION['user']['id'], 'rank')) >= 6)
  276. {
  277. $_SESSION["in_hk"] = true;
  278. header("Location:".$_CONFIG['hotel']['url']."/ase/dash");
  279. exit;
  280. }
  281. else
  282. {
  283. $template->form->error = '<div class="alert alert-error">Access denied.</div>';
  284. return;
  285. }
  286. }
  287. else
  288. {
  289. $template->form->error = '<div class="alert alert-error">Password incorrect.</div>';
  290. return;
  291. }
  292. }
  293. else
  294. {
  295. $template->form->error = 'Username does not exist!';
  296. return;
  297. }
  298. }
  299.  
  300. $template->form->unsetData();
  301. }
  302. }
  303.  
  304. final public function help()
  305. {
  306. global $template, $_CONFIG;
  307. $template->form->setData();
  308.  
  309. if(isset($template->form->help))
  310. {
  311. $to = $_CONFIG['hotel']['email'];
  312. $subject = "Help from HabPixel user - " . $this->getInfo($_SESSION['user']['id'], 'username');
  313. $body = $template->form->question;
  314.  
  315. if (mail($to, $subject, $body))
  316. {
  317. $template->form->error = 'Message successfully sent! We will answer you shortly!';
  318. }
  319. else
  320. {
  321. $template->form->error = 'Message delivery failed.';
  322. }
  323. }
  324. }
  325.  
  326. /*-------------------------------Account settings-------------------------------------*/
  327.  
  328. final public function updateAccount()
  329. {
  330. global $template, $_CONFIG, $core, $engine;
  331.  
  332. if(isset($_POST['account']))
  333. {
  334.  
  335. if(isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30 && $_POST['acc_motto'] != $this->getInfo($_SESSION['user']['id'], 'motto'))
  336. {
  337. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  338. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  339. exit;
  340. }
  341. else
  342. {
  343. $template->form->error = 'Motto is fout.';
  344. }
  345.  
  346. if(isset($_POST['acc_email']) && $_POST['acc_email'] != $this->getInfo($_SESSION['user']['id'], 'mail'))
  347. {
  348. if($this->validEmail($_POST['acc_email']))
  349. {
  350. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  351. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  352. exit;
  353. }
  354. else
  355. {
  356. $template->form->error = 'Email is fout';
  357. return;
  358. }
  359. }
  360.  
  361. if(!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password']))
  362. {
  363. if($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password'])))
  364. {
  365. if(strlen($_POST['acc_new_password']) >= 8)
  366. {
  367. $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  368. header('Location: '.$_CONFIG['hotel']['url'].'/me');
  369. exit;
  370. }
  371. else
  372. {
  373. $template->form->error = 'Wachtwoord is te kort!';
  374. return;
  375. }
  376. }
  377. else
  378. {
  379. $template->form->error = 'Fout wachwoord ingevoerd!';
  380. return;
  381. }
  382. }
  383. }
  384. }
  385.  
  386.  
  387. final public function turnOn($k)
  388. {
  389. $j = $this->getID($k);
  390. $this->createSSO($j);
  391. $_SESSION['user']['id'] = $j;
  392. $this->cacheUser($j);
  393. unset($j);
  394. }
  395.  
  396. /*-------------------------------Loggin forgotten-------------------------------------*/
  397.  
  398. final public function forgotten()
  399. {
  400. }
  401.  
  402. /*-------------------------------Create SSO auth_ticket-------------------------------------*/
  403.  
  404. final public function createSSO($k)
  405. {
  406. $sessionKey = 'Trito-Hotel-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  407.  
  408. $this->updateUser($k, 'auth_ticket', $sessionKey);
  409.  
  410. unset($sessionKey);
  411. }
  412.  
  413. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  414.  
  415. final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender, $seckey)
  416. {
  417. global $engine;
  418. $sessionKey = 'RevCMS-Hotel-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  419. $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 . "')");
  420. unset($sessionKey);
  421.  
  422. }
  423.  
  424. final public function deleteUser($k)
  425. {
  426. global $engine;
  427. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  428. $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  429. $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  430. }
  431.  
  432. final public function updateUser($k, $key, $value)
  433. {
  434. global $engine;
  435. $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  436. $_SESSION['user'][$key] = $engine->secure($value);
  437. }
  438.  
  439. /*-------------------------------Handling user information-------------------------------------*/
  440.  
  441. final public function cacheUser($k)
  442. {
  443. global $engine;
  444. $userInfo = $engine->fetch_assoc("SELECT username, rank, motto, mail, credits, activity_points, look, auth_ticket, ip_last FROM users WHERE id = '" . $k . "' LIMIT 1");
  445.  
  446. foreach($userInfo as $key => $value)
  447. {
  448. $this->setInfo($key, $value);
  449. }
  450. }
  451.  
  452. final public function setInfo($key, $value)
  453. {
  454. global $engine;
  455. $_SESSION['user'][$key] = $engine->secure($value);
  456. }
  457.  
  458. final public function getInfo($k, $key)
  459. {
  460. global $engine;
  461. if(!isset($_SESSION['user'][$key]))
  462. {
  463. $value = $engine->result("SELECT $key FROM users WHERE id = '" . $engine->secure($k) . "' LIMIT 1");
  464. if($value != null)
  465. {
  466. $this->setInfo($key, $value);
  467. }
  468. }
  469.  
  470. return $_SESSION['user'][$key];
  471. }
  472.  
  473.  
  474.  
  475. /*-------------------------------Get user ID or Username-------------------------------------*/
  476.  
  477. final public function getID($k)
  478. {
  479. global $engine;
  480. return $engine->result("SELECT id FROM users WHERE username = '" . $engine->secure($k) . "' LIMIT 1");
  481. }
  482.  
  483. final public function getUsername($k)
  484. {
  485. global $engine;
  486. return $this->getInfo($_SESSION['user']['id'], 'username');
  487. }
  488.  
  489. }
  490. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement