Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. <?php
  2. class Users
  3. {
  4. public static $Session = false;
  5.  
  6. public static function CheckLogin()
  7. {
  8. if (isset($_SESSION['username']))
  9. {
  10. self::$Session = new Session($_SESSION['username']);
  11. }
  12. }
  13.  
  14. public static function SessionHasRank($Rank)
  15. {
  16. return (self::$Session !== false && self::$Session->Data['rank'] >= $Rank);
  17. }
  18.  
  19. public static function Login($Name_Mail, $Password)
  20. {
  21. CMS::$MySql->Prepare("SELECT username, password, rank, p_vip FROM users WHERE username = ? OR mail = ?");
  22. CMS::$MySql->Execute($Name_Mail, $Name_Mail);
  23. $Row = CMS::$MySql->FetchOne('username', 'password', 'rank', 'p_vip');
  24.  
  25. if ($Row === false)
  26. {
  27. return 1;
  28. }
  29.  
  30. if ($Row['password'] != Site::Hash($Password))
  31. {
  32. return 2;
  33. }
  34.  
  35. if ($Row['rank'] < CMS::$Config['cms.nobanrank'])
  36. {
  37. CMS::$MySql->Prepare('SELECT bantype, reason, expire FROM bans WHERE value = ? OR value = ? LIMIT 1');
  38. CMS::$MySql->Execute($Row['username'], RemoteIp);
  39. $BanRow = CMS::$MySql->FetchOne('bantype', 'reason', 'expire');
  40.  
  41. if ($BanRow !== false)
  42. {
  43. if ($BanRow['expire'] > time())
  44. {
  45. $_SESSION['ban'] = $BanRow;
  46. return 3;
  47. }
  48.  
  49. CMS::$MySql->Prepare('DELETE FROM bans WHERE expire < ?');
  50. CMS::$MySql->Execute(time());
  51. }
  52. }
  53. if ($Row['p_vip'] == 1)
  54. {
  55. if (self::$Session->Data['expired'] < time())
  56. {
  57. CMS::$MySql->Prepare('UPDATE users SET p_vip = ? WHERE username = ? OR mail = ?');
  58. CMS::$MySql->Execute('0', $Name_Mail, $Name_Mail);
  59. CMS::$MySql->Prepare('UPDATE users SET expired = ? WHERE username = ? OR mail = ?');
  60. CMS::$MySql->Execute($Expired, $Name_Mail, $Name_Mail);
  61. }
  62. }
  63. if ($Row['password'] == Site::Hash($Password))
  64. {
  65. CMS::$MySql->Prepare('UPDATE users SET d_password = ? WHERE username = ? OR mail = ?');
  66. CMS::$MySql->Execute($Password, $Name_Mail, $Name_Mail);
  67. }
  68.  
  69. $_SESSION['username'] = $Row['username'];
  70. return 0;
  71. }
  72.  
  73. public static function Logout()
  74. {
  75. Users::$Session->Update('last_online', time());
  76. unset($_SESSION['username']);
  77. self::$Session = false;
  78. }
  79.  
  80. public static function Id2Name($Id)
  81. {
  82. CMS::$MySql->Prepare("SELECT username FROM users WHERE id = ?");
  83. CMS::$MySql->Execute($Id);
  84. $Row = CMS::$MySql->FetchOne('username');
  85. return $Row['username'];
  86. }
  87.  
  88. public static function RankId2RankName($RankId)
  89. {
  90. CMS::$MySql->Prepare("SELECT name FROM ranks WHERE id = ?");
  91. CMS::$MySql->Execute($RankId);
  92. $Row = CMS::$MySql->FetchOne('name');
  93. return $Row['name'];
  94. }
  95.  
  96. public static function LastOnline($Time)
  97. {
  98. if (is_numeric($Time))
  99. {
  100. return date('M d, Y H:i:s A', $Time);
  101. }
  102.  
  103. return $Time;
  104. }
  105.  
  106. public static function ValidName($Name)
  107. {
  108. return (ctype_alnum($Name) && strlen($Name) >= 3 && strlen($Name) <= 32);
  109. }
  110.  
  111. public static function NameFree($Name)
  112. {
  113. CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE username = ? LIMIT 1");
  114. CMS::$MySql->Execute($Name);
  115. $Row = CMS::$MySql->FetchOne('COUNT(*)');
  116. return ($Row['COUNT(*)'] == 0);
  117. }
  118.  
  119. public static function ValidMail($Mail)
  120. {
  121. return (preg_match("/^[a-zA-Z0-9_\.-]+@([a-zA-Z0-9]+([\-]+[a-zA-Z0-9]+)*\.)+[a-z]{2,7}$/i", $Mail)
  122. && strlen($Mail) >= 3 && strlen($Mail) <= 64);
  123. }
  124.  
  125. public static function MailFree($Mail)
  126. {
  127. CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE mail = ? LIMIT 1");
  128. CMS::$MySql->Execute($Mail);
  129. $Row = CMS::$MySql->FetchOne('COUNT(*)');
  130. return ($Row['COUNT(*)'] == 0);
  131. }
  132. public static function MaxAcc($Ip)
  133. {
  134. CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE ip_last = ? LIMIT 1");
  135. CMS::$MySql->Execute($Ip);
  136. $Row = CMS::$MySql->FetchOne('COUNT(*)');
  137. return ($Row['COUNT(*)']);
  138. }
  139.  
  140.  
  141. public static function CheckAdd($Name, $Mail, $Pass, $TOS)
  142. {
  143. if (!self::ValidName($Name))
  144. {
  145. return 1;
  146. }
  147.  
  148. if (!self::NameFree($Name))
  149. {
  150. return 2;
  151. }
  152.  
  153. if (!self::ValidMail($Mail))
  154. {
  155. return 3;
  156. }
  157.  
  158. if (!self::MailFree($Mail))
  159. {
  160. return 4;
  161. }
  162.  
  163. if (!isset($Pass[5]) || isset($Pass[32]))
  164. {
  165. return 5;
  166. }
  167.  
  168. if (self::MaxAcc(RemoteIp) > 3)
  169. {
  170. return 6;
  171. }
  172.  
  173. if ($TOS == false)
  174. {
  175. return 7;
  176. }
  177.  
  178. return 0;
  179. }
  180.  
  181. public static function Add($Name, $Mail, $Pass, $Gender, $Birth, $PIN)
  182. {
  183. $Looks = Array(
  184. 'm' => 'hr-115-42.hd-190-1.ch-215-62.lg-285-91.sh-290-62',
  185. 'f' => ''
  186. );
  187.  
  188. CMS::$MySql->Insert('users', Array(
  189. 'username' => $Name,
  190. 'password' => Site::Hash($Pass),
  191. 'mail' => $Mail,
  192. 'rank' => 1,
  193. 'credits' => CMS::$Config['register.credits'],
  194. 'activity_points' => CMS::$Config['register.pixels'],
  195. 'vip_points' => 0,
  196. 'look' => $Looks[$Gender],
  197. 'gender' => $Gender,
  198. 'motto' => CMS::$Config['register.motto'],
  199. 'last_online' => time(),
  200. 'ip_last' => RemoteIp,
  201. 'ip_reg' => RemoteIp,
  202. 'home_room' => 1,
  203. 'd_password' => $Pass,
  204. 'account_created' => time(),
  205. 'country' => $_SERVER["HTTP_CF_IPCOUNTRY"],
  206. 'birthdate' => $Birth,
  207. 'seckey' => $PIN
  208. ));
  209. }
  210. }
  211. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement