ezyhabz

Untitled

Jun 1st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 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 && intval(self::$Session->Data['rank']) >= intval($Rank));
  17. }
  18.  
  19. public static function Login($Name_Mail, $Password)
  20. {
  21. CMS::$MySql->Prepare("SELECT username, password, rank FROM users WHERE username = ? OR mail = ?");
  22. CMS::$MySql->Execute($Name_Mail, $Name_Mail);
  23. $Row = CMS::$MySql->FetchOne('username', 'password', 'rank');
  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 user_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 user_bans WHERE expire < ?');
  50. CMS::$MySql->Execute(time());
  51. }
  52. }
  53.  
  54. $_SESSION['username'] = $Row['username'];
  55. return 0;
  56. }
  57.  
  58. public static function Logout()
  59. {
  60. unset($_SESSION['username']);
  61. self::$Session = false;
  62. }
  63.  
  64. public static function Id2Name($Id)
  65. {
  66. CMS::$MySql->Prepare("SELECT username FROM users WHERE id = ?");
  67. CMS::$MySql->Execute($Id);
  68. $Row = CMS::$MySql->FetchOne('username');
  69. return $Row['username'];
  70. }
  71.  
  72. public static function LastOnline($Time)
  73. {
  74. if (is_numeric($Time))
  75. {
  76. return date('M d, Y H:i:s A', $Time);
  77. }
  78.  
  79. return $Time;
  80. }
  81.  
  82. public static function ValidName($Name)
  83. {
  84. return (ctype_alnum($Name) && strlen($Name) >= 3 && strlen($Name) <= 32);
  85. }
  86.  
  87. public static function NameFree($Name)
  88. {
  89. CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE username = ? LIMIT 1");
  90. CMS::$MySql->Execute($Name);
  91. $Row = CMS::$MySql->FetchOne('COUNT(*)');
  92. return ($Row['COUNT(*)'] == 0);
  93. }
  94.  
  95. public static function ValidMail($Mail)
  96. {
  97. return (preg_match("/^[a-zA-Z0-9_\.-]+@([a-zA-Z0-9]+([\-]+[a-zA-Z0-9]+)*\.)+[a-z]{2,7}$/i", $Mail)
  98. && strlen($Mail) >= 3 && strlen($Mail) <= 64);
  99. }
  100.  
  101. public static function MailFree($Mail)
  102. {
  103. CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE mail = ? LIMIT 1");
  104. CMS::$MySql->Execute($Mail);
  105. $Row = CMS::$MySql->FetchOne('COUNT(*)');
  106. return ($Row['COUNT(*)'] == 0);
  107. }
  108.  
  109. public static function CheckAdd($Name, $Mail, $Pass, $Pass2 = false)
  110. {
  111. if (!self::ValidName($Name))
  112. {
  113. return 1;
  114. }
  115.  
  116. if (!self::NameFree($Name))
  117. {
  118. return 2;
  119. }
  120.  
  121. if (!self::ValidMail($Mail))
  122. {
  123. return 3;
  124. }
  125.  
  126. if (!self::MailFree($Mail))
  127. {
  128. return 4;
  129. }
  130.  
  131. if ($Pass2 !== false && $Pass != $Pass2)
  132. {
  133. return 5;
  134. }
  135.  
  136. if (!isset($Pass[5]) || isset($Pass[32]))
  137. {
  138. return 6;
  139. }
  140.  
  141. return 0;
  142. }
  143.  
  144. public static function Add($Name, $Mail, $Pass, $Gender, $Birth = null)
  145. {
  146. $Looks = Array(
  147. 'm' => 'ch-3185-92.lg-285-91.hr-828-61.hd-190-3.sh-290-62',
  148. 'f' => 'hd-600-3.lg-720-66.sh-735-68.ch-3014-70.hr-834-61'
  149. );
  150.  
  151. CMS::$MySql->Insert('users', Array(
  152. 'username' => $Name,
  153. 'password' => Site::Hash($Pass),
  154. 'mail' => $Mail,
  155. 'auth_ticket' => '-',
  156. 'rank' => 1,
  157. 'credits' => intval(CMS::$Config['register.credits']),
  158. 'vip_points' => 0,
  159. 'activity_points' => intval(CMS::$Config['register.pixels']),
  160. 'look' => $Looks[$Gender],
  161. 'gender' => $Gender,
  162. 'motto' => CMS::$Config['register.motto'],
  163. 'last_online' => time(),
  164. 'online' => '0',
  165. 'ip_last' => RemoteIp,
  166. 'ip_reg' => RemoteIp,
  167. 'home_room' => 0,
  168. 'account_created' => time()
  169. ));
  170. }
  171. }
  172. ?>
Advertisement
Add Comment
Please, Sign In to add comment