Advertisement
Guest User

class.user.php norska

a guest
Feb 25th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.51 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['HTTP_CF_CONNECTING_IP'] . "'") == 199999)
  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['HTTP_CF_CONNECTING_IP']) == false)
  150. {
  151. if(!$this->hasClones($_SERVER['HTTP_CF_CONNECTING_IP']))
  152. {
  153. if(!isset($template->form->reg_gender)) { $template->form->reg_gender = 'M'; }
  154. if(!isset($template->form->reg_figure)) { $template->form->reg_figure = $_CONFIG['hotel']['figure']; }
  155.  
  156. $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));
  157.  
  158. $this->turnOn($template->form->reg_username);
  159.  
  160. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  161. exit;
  162. }
  163. else
  164. {
  165. $template->form->error = 'Sorry, but you cannot register twice';
  166. }
  167. }
  168. else
  169. {
  170. $template->form->error = 'Sorry, it appears you are IP banned.<br />';
  171. $template->form->error .= 'Reason: ' . $this->getReason($_SERVER['HTTP_CF_CONNECTING_IP']);
  172. return;
  173. }
  174. }
  175. else
  176. {
  177. $template->form->error = 'Password does not match repeated password';
  178. return;
  179. }
  180.  
  181. }
  182. else
  183. {
  184. $template->form->error = 'Password must have more than 6 characters';
  185. return;
  186. }
  187. }
  188. else
  189. {
  190. $template->form->error = 'Email: <b>' . $template->form->reg_email . '</b> is already registered';
  191. return;
  192. }
  193. }
  194. else
  195. {
  196. $template->form->error = 'Email is not valid';
  197. return;
  198. }
  199. }
  200. else
  201. {
  202. $template->form->error = 'Username is already registered';
  203. return;
  204. }
  205. }
  206. else
  207. {
  208. $template->form->error = 'Username is invalid';
  209. return;
  210. }
  211. }
  212. }
  213.  
  214. final public function login()
  215. {
  216. global $template, $_CONFIG, $core;
  217.  
  218. if(isset($_POST['login']))
  219. {
  220. $template->form->setData();
  221. unset($template->form->error);
  222.  
  223. if($this->nameTaken($template->form->log_username))
  224. {
  225. if($this->isBanned($_SERVER['HTTP_CF_CONNECTING_IP']) == false)
  226. {
  227. if($this->isBanned($template->form->log_username) == false)
  228. {
  229. if($this->userValidation($template->form->log_username, $core->hashed($template->form->log_password)))
  230. {
  231. $this->turnOn($template->form->log_username);
  232. $this->updateUser($_SESSION['user']['id'], 'ip_last', $_SERVER['HTTP_CF_CONNECTING_IP']);
  233. $this->updateUser($_SESSION['user']['id'], 'ip_reg', $_SERVER['HTTP_CF_CONNECTING_IP']);
  234. $template->form->unsetData();
  235. header('Location: ' . $_CONFIG['hotel']['url'] . '/me');
  236. exit;
  237. }
  238. else
  239. {
  240. $template->form->error = 'Details do not match';
  241. return;
  242. }
  243. }
  244. else
  245. {
  246. $template->form->error = 'Sorry, användaren har blivit (Portad) ifrån hotellet du kan överklaga ditt ban på Support@Habbihotel.org<br />';
  247. $template->form->error .= 'Anledning: ' . $this->getReason($template->form->log_username);
  248. return;
  249. }
  250. }
  251. else
  252. {
  253. $template->form->error = 'Sorry, detta kontot har blivit (IP) portad från hotellet, Du kan överklaga ditt ban skicka mail till Support@Habbihotel.org<br />';
  254. $template->form->error .= 'Anledning: ' . $this->getReason($_SERVER['HTTP_CF_CONNECTING_IP']);
  255. return;
  256. }
  257. }
  258. else
  259. {
  260. $template->form->error = 'Username does not exist';
  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')) >= 6)
  282. {
  283. $_SESSION["in_hk"] = true;
  284. header("Location:".$_CONFIG['hotel']['url']."/ase/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']) < 50 && $_POST['acc_motto'] != $this->getInfo($_SESSION['user']['id'], 'motto'))
  342. {
  343. $this->updateUser($_SESSION['user']['id'], 'motto', $engine->secure($_POST['acc_motto']));
  344. $template->form->successfully = 'Innstillingene dine ble lagret!';
  345. }
  346. if(isset($_POST['acc_avatar']) && strlen($_POST['acc_avatar']) < 50 && $_POST['acc_avatar'] != $this->getInfo($_SESSION['user']['id'], 'profile_avatar'))
  347. {
  348. $this->updateUser($_SESSION['user']['id'], 'profile_avatar', $engine->secure($_POST['acc_avatar']));
  349. $template->form->successfully = 'Innstillingene dine ble lagret!';
  350. }
  351. if(isset($_POST['acc_bp']) && $_POST['acc_bp'] != $this->getInfo($_SESSION['user']['id'], 'background_pic'))
  352. {
  353. $this->updateUser($_SESSION['user']['id'], 'background_pic', $engine->secure($_POST['acc_bp']));
  354. $template->form->successfully = 'Innstillingene dine ble lagret!';
  355. }
  356. if(isset($_POST['acc_bd']) && strlen($_POST['acc_bd']) < 50 && $_POST['acc_bd'] != $this->getInfo($_SESSION['user']['id'], 'backdrop'))
  357. {
  358. $this->updateUser($_SESSION['user']['id'], 'backdrop', $engine->secure($_POST['acc_bd']));
  359. $template->form->successfully = 'Innstillingene dine ble lagret!';
  360. }
  361. if(isset($_POST['acc_lang']) && strlen($_POST['acc_lang']) < 50 && $_POST['acc_lang'] != $this->getInfo($_SESSION['user']['id'], 'lang'))
  362. {
  363. $this->updateUser($_SESSION['user']['id'], 'lang', $engine->secure($_POST['acc_lang']));
  364. $template->form->successfully = 'Innstillingene dine ble lagret!';
  365. }
  366. if(isset($_POST['acc_yt']) && strlen($_POST['acc_yt']) < 50 && $_POST['acc_yt'] != $this->getInfo($_SESSION['user']['id'], 'youtube_video'))
  367. {
  368. $this->updateUser($_SESSION['user']['id'], 'youtube_video', $engine->secure($_POST['acc_yt']));
  369. $template->form->successfully = 'Innstillingene dine ble lagret!';
  370. }
  371.  
  372. if(isset($_POST['acc_style']) && strlen($_POST['acc_style']) < 50 && $_POST['acc_style'] != $this->getInfo($_SESSION['user']['id'], 'name_styling'))
  373. {
  374. $this->updateUser($_SESSION['user']['id'], 'name_styling', $engine->secure($_POST['acc_style']));
  375. $template->form->successfully = 'Innstillingene dine ble lagret!';
  376. }
  377.  
  378. if(isset($_POST['acc_fr']) && strlen($_POST['acc_fr']) < 2 && $_POST['acc_fr'] != $this->getInfo($_SESSION['user']['id'], 'block_newfriends'))
  379. {
  380. $this->updateUser($_SESSION['user']['id'], 'block_newfriends', $engine->secure($_POST['acc_fr']));
  381. $template->form->successfully = 'Innstillingene dine ble lagret!';
  382. }
  383.  
  384. if(isset($_POST['acc_bt']) && strlen($_POST['acc_bt']) < 2 && $_POST['acc_bt'] != $this->getInfo($_SESSION['user']['id'], 'accept_trading'))
  385. {
  386. $this->updateUser($_SESSION['user']['id'], 'accept_trading', $engine->secure($_POST['acc_bt']));
  387. $template->form->successfully = 'Innstillingene dine ble lagret!';
  388. }
  389.  
  390. if(isset($_POST['acc_email']) && $_POST['acc_email'] != $this->getInfo($_SESSION['user']['id'], 'mail'))
  391. {
  392. if($this->validEmail($_POST['acc_email']))
  393. {
  394. $this->updateUser($_SESSION['user']['id'], 'mail', $engine->secure($_POST['acc_email']));
  395. header('Location: '.$_CONFIG['hotel']['url'].'/account');
  396. exit;
  397. }
  398. else
  399. {
  400. $template->form->error = 'Email is not valid';
  401. return;
  402. }
  403. }
  404. if(isset($_POST['acc_about']) && strlen($_POST['acc_about']) < 22342342342 && $_POST['acc_about'] != $this->getInfo($_SESSION['user']['id'], 'bio_content'))
  405. {
  406. $this->updateUser($_SESSION['user']['id'], 'bio_content', $_POST['acc_about']);
  407. $template->form->successfully = 'Innstillingene dine ble lagret!';
  408. }
  409.  
  410. if(!empty($_POST['acc_old_password']) && !empty($_POST['acc_new_password']) && !empty($_POST['acc_rep_password']))
  411. {
  412. if($this->userValidation($this->getInfo($_SESSION['user']['id'], 'username'), $core->hashed($_POST['acc_old_password'])))
  413. {
  414. if($_POST['acc_new_password'] != $_POST['acc_rep_password']) {
  415. $template->form->error = 'Passordene du skrev inn er ikke like!';
  416. return;
  417. }
  418. if(strlen($_POST['acc_new_password']) >= 8)
  419. {
  420. $this->updateUser($_SESSION['user']['id'], 'password', $core->hashed($_POST['acc_new_password']));
  421. $template->form->successfully = 'Ditt nye passord ble lagret!';
  422. }
  423. else
  424. {
  425. $template->form->error = 'Det nye passordet er for kort!';
  426. return;
  427. }
  428. }
  429. else
  430. {
  431. $template->form->error = 'Nåværende passord er feil!';
  432. return;
  433. }
  434. }
  435.  
  436. }
  437.  
  438. }
  439.  
  440.  
  441. final public function turnOn($k)
  442. {
  443. $j = $this->getID($k);
  444. $this->createSSO($j);
  445. $_SESSION['user']['id'] = $j;
  446. $this->cacheUser($j);
  447. unset($j);
  448. }
  449.  
  450. /*-------------------------------Loggin forgotten-------------------------------------*/
  451.  
  452. final public function forgotten()
  453. {
  454. }
  455.  
  456. /*-------------------------------Create SSO auth_ticket-------------------------------------*/
  457.  
  458. final public function createSSO($k)
  459. {
  460. $sessionKey = 'Malefi-'.rand(9,9999999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  461.  
  462. $this->updateUser($k, 'auth_ticket', $sessionKey);
  463.  
  464. unset($sessionKey);
  465. }
  466.  
  467. /*-------------------------------Adding/Updating/Deleting users-------------------------------------*/
  468.  
  469. final public function addUser($username, $password, $email, $motto, $credits, $pixels, $rank, $figure, $gender, $seckey)
  470. {
  471. global $engine;
  472. $sessionKey = 'Malefi-'.rand(9,9999999).'/'.substr(sha1(time()).'/'.rand(9,9999999).'/'.rand(9,9999999).'/'.rand(9,9999999),0,33);
  473. $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['HTTP_CF_CONNECTING_IP'] . "', '" . $_SERVER['HTTP_CF_CONNECTING_IP'] . "', '" . time() . "', '" . time() . "', '" . $sessionKey . "')");
  474. unset($sessionKey);
  475.  
  476. }
  477.  
  478. final public function deleteUser($k)
  479. {
  480. global $engine;
  481. $engine->query("DELETE FROM users WHERE id = '" . $k . "' LIMIT 1");
  482. $engine->query("DELETE FROM items WHERE userid = '" . $k . "' LIMIT 1");
  483. $engine->query("DELETE FROM rooms WHERE ownerid = '" . $k . "' LIMIT 1");
  484. }
  485.  
  486. final public function updateUser($k, $key, $value)
  487. {
  488. global $engine;
  489. $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  490. $_SESSION['user'][$key] = $engine->secure($value);
  491. }
  492. final public function updateIp($k, $key, $value)
  493. {
  494. global $engine;
  495. $engine->query("UPDATE users SET " . $key . " = '" . $engine->secure($value) . "' WHERE id = '" . $k . "' LIMIT 1");
  496. $_SESSION['user'][$key] = $engine->secure($value);
  497. }
  498.  
  499. /*-------------------------------Handling user information-------------------------------------*/
  500.  
  501. final public function cacheUser($k)
  502. {
  503. global $engine;
  504. $userInfo = $engine->fetch_assoc("SELECT username, rank, motto, mail, credits, activity_points, look, auth_ticket, ip_last FROM users WHERE id = '" . $k . "' LIMIT 1");
  505.  
  506. foreach($userInfo as $key => $value)
  507. {
  508. $this->setInfo($key, $value);
  509. }
  510. }
  511.  
  512. final public function setInfo($key, $value)
  513. {
  514. global $engine;
  515. $_SESSION['user'][$key] = $engine->secure($value);
  516. }
  517.  
  518. final public function getInfo($k, $key)
  519. {
  520. global $engine;
  521. if(!isset($_SESSION['user'][$key]))
  522. {
  523. $value = $engine->result("SELECT $key FROM users WHERE id = '" . $engine->secure($k) . "' LIMIT 1");
  524. if($value != null)
  525. {
  526. $this->setInfo($key, $value);
  527. }
  528. }
  529.  
  530. return $_SESSION['user'][$key];
  531. }
  532.  
  533.  
  534.  
  535. /*-------------------------------Get user ID or Username-------------------------------------*/
  536.  
  537. final public function getID($k)
  538. {
  539. global $engine;
  540. return $engine->result("SELECT id FROM users WHERE username = '" . $engine->secure($k) . "' LIMIT 1");
  541. }
  542.  
  543. final public function getUsername($k)
  544. {
  545. global $engine;
  546. return $this->getInfo($_SESSION['user']['id'], 'username');
  547. }
  548.  
  549. }
  550. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement