Guest User

Untitled

a guest
Apr 20th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.70 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 = '" . md5($_POST['log_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'] . "'") == 1)
  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. $this->turnOn($template->form->reg_username);
  158.  
  159. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  160. exit;
  161. }
  162. else
  163. {
  164. $template->form->error = 'Sorry, but you cannot register twice';
  165. }
  166. }
  167. else
  168. {
  169. $template->form->error = 'Sorry, it appears you are IP banned.<br />';
  170. $template->form->error .= 'Reason: ' . $this->getReason($_SERVER['REMOTE_ADDR']);
  171. return;
  172. }
  173. }
  174. else
  175. {
  176. $template->form->error = 'Password does not match repeated password';
  177. return;
  178. }
  179.  
  180. }
  181. else
  182. {
  183. $template->form->error = 'Password must have more than 6 characters';
  184. return;
  185. }
  186. }
  187. else
  188. {
  189. $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> is already registered';
  190. return;
  191. }
  192. }
  193. else
  194. {
  195. $template->form->error = 'Email is not valid';
  196. return;
  197. }
  198. }
  199. else
  200. {
  201. $template->form->error = 'Username is already registered';
  202. return;
  203. }
  204. }
  205. else
  206. {
  207. $template->form->error = 'Username is invalid';
  208. return;
  209. }
  210. }
  211. }
  212.  
  213. final public function login()
  214. {
  215. global $template, $_CONFIG, $core;
  216.  
  217. if(isset($_POST['login']))
  218. {
  219. $template->form->setData();
  220. unset($template->form->error);
  221.  
  222. if($this->nameTaken($template->form->log_username))
  223. {
  224. if($this->isBanned($template->form->log_username) == false || $this->isBanned($_SERVER['REMOTE_ADDR']) == false)
  225. {
  226. if($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password)))
  227. {
  228. $this->turnOn($template->form->log_username);
  229. $this->updateUser($_SESSION['user']['id'], 'ip_last', $_SERVER['REMOTE_ADDR']);
  230. $template->form->unsetData();
  231. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  232. exit;
  233. }
  234. else
  235. {
  236. $template->form->error = 'Details do not match';
  237. return;
  238. }
  239. }
  240. else
  241. {
  242. $template->form->error = 'Sorry, it appears this user is banned<br />';
  243. $template->form->error .= 'Reason: ' . $this->getReason($template->form->log_username);
  244. return;
  245. }
  246. }
  247. else
  248. {
  249. $template->form->error = 'Username does not exist';
  250. return;
  251. }
  252. }
  253. }
  254.  
  255. final public function loginHK()
  256. {
  257. global $template, $_CONFIG, $core;
  258.  
  259. if(isset($_POST['login']))
  260. {
  261. $template->form->setData();
  262. unset($template->form->error);
  263.  
  264. if(isset($template->form->username) && isset($template->form->password))
  265. {
  266. if($this->nameTaken($template->form->username))
  267. {
  268. if($this->userValidation($template->form->username, $core->hashed($template->form->password)))
  269. {
  270. if(($this->getInfo($_SESSION['user']['id'], 'rank')) >= 4)
  271. {
  272. $_SESSION["in_hk"] = true;
  273. header("Location:".$_CONFIG['hotel']['url']."/ase/dash");
  274. exit;
  275. }
  276. else
  277. {
  278. $template->form->error = 'Incorrect access level.';
  279. return;
  280. }
  281. }
  282. else
  283. {
  284. $template->form->error = 'Incorrect password.';
  285. return;
  286. }
  287. }
  288. else
  289. {
  290. $template->form->error = 'User does not exist.';
  291. return;
  292. }
  293. }
  294.  
  295. $template->form->unsetData();
  296. }
  297. }
  298.  
  299. final public function help()
  300. {
  301. global $template, $_CONFIG;
  302. $template->form->setData();
  303.  
  304. if(isset($template->form->help))
  305. {
  306. $to = $_CONFIG['hotel']['email'];
  307. $subject = "Help from RevCMS user - " . $this->getInfo($_SESSION['user']['id'], 'username');
  308. $body = $template->form->question;
  309.  
  310. if (mail($to, $subject, $body))
  311. {
  312. $template->form->error = 'Message successfully sent! We will answer you shortly!';
  313. }
  314. else
  315. {
  316. $template->form->error = 'Message delivery failed.';
  317. }
  318. }
  319. }
  320.  
  321. /*-------------------------------Account settings-------------------------------------*/
  322.  
  323. final public function updateAccount()
  324. {
  325. global $template, $_CONFIG, $core, $engine;
  326.  
  327. if(isset($_POST['account']))
  328. {
  329.  
  330. if(isset($_POST['acc_motto']) && strlen($_POST['acc_motto']) < 30 && $_POST['acc_motto'] != $this->getInfo($_SESSION['user']['id'], 'motto'))
  331. {
  332. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  333. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  334. exit;
  335. }
  336. else
  337. {
  338. $template->form->error = 'Motto is invalid.';
  339. }
  340.  
  341. if(isset($_POST['acc_email']) && $_POST['acc_email'] != $this->getInfo($_SESSION['user']['id'], 'mail'))
  342. {
  343. if($this->validEmail($_POST['acc_email']))
  344. {
  345. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  346. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  347. exit;
  348. }
  349. else
  350. {
  351. $template->form->error = 'Email is not valid';
  352. return;
  353. }
  354. }
  355.  
  356. //update password by [cranavvo] for habplus, since revCMS doesn't support special chars he wanted a scrip that does.. so here it is ;)
  357. //p.s.s.s.s.s.s.s.s.s.s.s.s.s.s..s nothing.
  358.  
  359. //lets get the user informatio first.
  360. $getUserInfoLikeNow = mysql_query("SELECT * FROM users WHERE id='". $_SESSION['user']['id'] ."'");
  361. while($profile = mysql_fetch_assoc($getUserInfoLikeNow)){
  362. $current_password = $profile['password'];
  363. }
  364. if($_POST['acc_new_password'] && $_POST['acc_old_password']){
  365.  
  366. if(md5($_POST['acc_old_password']) == $current_password){
  367.  
  368. if(strlen($_POST['acc_new_password'])<33 || strlen($_POST['acc_new_password']>3)){
  369.  
  370. $newPass = mysql_query("UPDATE users SET password='". md5($_POST['acc_new_password']) ."' WHERE id='". $_SESSION['user']['id'] ."'");
  371. if($newPass){
  372.  
  373. echo "<div class='acc_error' onClick='getLost();' style='font-weight:bold; color:white; padding:10px; background-color:#CCFF33; border-width:2px; border-style:solid; border-color:#8AB800;'>Your password was updated successfully!</div></div>";
  374.  
  375. }
  376. else
  377. echo "<div class='acc_error' onClick='getLost();' style='font-weight:bold; color:white; padding:10px; background-color:#FF4747; border-width:2px; border-style:solid; border-color:#CC0000;'>There was a problem processing the query your password was not updated!</div>";
  378.  
  379.  
  380. }
  381. else
  382. echo "<div class='acc_error' onClick='getLost();' style='font-weight:bold; color:white; padding:10px; background-color:#FF4747; border-width:2px; border-style:solid; border-color:#CC0000;'>Password is bigger then 32 characters or it's smaller then 4 characters!</div>";
  383.  
  384. }
  385. else
  386. echo "<div class='acc_error' onClick='getLost();' style='font-weight:bold; color:white; padding:10px; background-color:#FF4747; border-width:2px; border-style:solid; border-color:#CC0000;'>Your current password doesn't match the one you entered!</div>";
  387.  
  388.  
  389. }
  390.  
  391. }
  392. }
  393.  
  394.  
  395. final public function turnOn($k)
  396. {
  397. $j = $this->getID($k);
  398. $this->createSSO($j);
  399. $_SESSION['user']['id'] = $j;
  400. $this->cacheUser($j);
  401. unset($j);
  402. }
  403.  
  404. /*-------------------------------Loggin forgotten-------------------------------------*/
  405.  
  406. final public function forgotten()
  407. {
  408. global $template, $_CONFIG, $core;
  409.  
  410. if(isset($_POST['forgot']))
  411. {
  412.  
  413. $template->form->setData();
  414. unset($template->form->error);
  415.  
  416. if($this->nameTaken($template->form->for_username))
  417. {
  418. if(strlen($template->form->for_password) > 6)
  419. {
  420. if($this->getInfo($this->getID($template->form->for_username), 'seckey') == $core->hashed($template->form->for_key))
  421. {
  422. $this->updateUser($this->getID($template->form->for_username), 'password', $core->hashed($template->form->for_password));
  423. $template->form->error = 'Account recovered! Go <b><a href="index">here</a></b> to login!';
  424. return;
  425. }
  426. else
  427. {
  428. $template->form->error = 'Secret key is incorrect';
  429. return;
  430. }
  431. }
  432. else
  433. {
  434. $template->form->error = 'Password must have more than 6 characters.';
  435. return;
  436. }
  437. }
  438. else
  439. {
  440. $template->form->error = 'Username does not exist';
  441. return;
  442. }
  443. }
  444. }
  445.  
  446. /*-------------------------------Create SSO auth_ticket-------------------------------------*/
  447.  
  448. final public function createSSO($k)
  449. {
  450. $sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  451.  
  452. $this->updateUser($k, 'auth_ticket', $sessionKey);
  453.  
  454. unset($sessionKey);
  455. }
  456.  
  457. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  458.  
  459. final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender, $seckey)
  460. {
  461. global $engine;
  462. $code = rand(1111111, 999999999999999);
  463. $sessionKey = 'RevCMS-'.rand(9,999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  464. $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 . "', '" . md5($_POST['reg_password']) . "', '" . $email . "', '" . $motto . "', '" . $credits . "', '" . $pixels . "', '" . $rank . "', '" . $figure . "', '" . $gender . "', '" . $seckey . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . time() . "', '" . time() . "', '" . $sessionKey . "')");
  465. $engine->query("INSERT INTO credit_vouchers (code, value, user) VALUES ('$code', '500', '" . mysql_real_escape_string(strip_tags($_POST['reg_referal'])) . "')");
  466. unset($sessionKey);
  467.  
  468. }
  469.  
  470. final public function deleteUser($k)
  471. {
  472. global $engine;
  473. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  474. $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  475. $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  476. }
  477.  
  478. final public function updateUser($k, $key, $value)
  479. {
  480. global $engine;
  481. $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  482. $_SESSION['user'][$key] = $engine->secure($value);
  483. }
  484.  
  485. /*-------------------------------Handling user information-------------------------------------*/
  486.  
  487. final public function cacheUser($k)
  488. {
  489. global $engine;
  490. $userInfo = $engine->fetch_assoc("SELECT username, rank, motto, mail, credits, activity_points, look, auth_ticket, ip_last FROM users WHERE id = '" . $k . "' LIMIT 1");
  491.  
  492. foreach($userInfo as $key => $value)
  493. {
  494. $this->setInfo($key, $value);
  495. }
  496. }
  497.  
  498. final public function setInfo($key, $value)
  499. {
  500. global $engine;
  501. $_SESSION['user'][$key] = $engine->secure($value);
  502. }
  503.  
  504. final public function getInfo($k, $key)
  505. {
  506. global $engine;
  507. if(!isset($_SESSION['user'][$key]))
  508. {
  509. $value = $engine->result("SELECT $key FROM users WHERE id = '" . $engine->secure($k) . "' LIMIT 1");
  510. if($value != null)
  511. {
  512. $this->setInfo($key, $value);
  513. }
  514. }
  515.  
  516. return $_SESSION['user'][$key];
  517. }
  518.  
  519.  
  520.  
  521. /*-------------------------------Get user ID or Username-------------------------------------*/
  522.  
  523. final public function getID($k)
  524. {
  525. global $engine;
  526. return $engine->result("SELECT id FROM users WHERE username = '" . $engine->secure($k) . "' LIMIT 1");
  527. }
  528.  
  529. final public function getUsername($k)
  530. {
  531. global $engine;
  532. return $this->getInfo($_SESSION['user']['id'], 'username');
  533. }
  534.  
  535. }
  536. ?>
Add Comment
Please, Sign In to add comment