Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Users
- {
- public static $Session = false;
- public static function CheckLogin()
- {
- if (isset($_SESSION['username']))
- {
- self::$Session = new Session($_SESSION['username']);
- }
- }
- public static function SessionHasRank($Rank)
- {
- return (self::$Session !== false && self::$Session->Data['rank'] >= $Rank);
- }
- public static function Login($Name_Mail, $Password)
- {
- CMS::$MySql->Prepare("SELECT username, password, rank, p_vip FROM users WHERE username = ? OR mail = ?");
- CMS::$MySql->Execute($Name_Mail, $Name_Mail);
- $Row = CMS::$MySql->FetchOne('username', 'password', 'rank', 'p_vip');
- if ($Row === false)
- {
- return 1;
- }
- if ($Row['password'] != Site::Hash($Password))
- {
- return 2;
- }
- if ($Row['rank'] < CMS::$Config['cms.nobanrank'])
- {
- CMS::$MySql->Prepare('SELECT bantype, reason, expire FROM bans WHERE value = ? OR value = ? LIMIT 1');
- CMS::$MySql->Execute($Row['username'], RemoteIp);
- $BanRow = CMS::$MySql->FetchOne('bantype', 'reason', 'expire');
- if ($BanRow !== false)
- {
- if ($BanRow['expire'] > time())
- {
- $_SESSION['ban'] = $BanRow;
- return 3;
- }
- CMS::$MySql->Prepare('DELETE FROM bans WHERE expire < ?');
- CMS::$MySql->Execute(time());
- }
- }
- if ($Row['p_vip'] == 1)
- {
- if (self::$Session->Data['expired'] < time())
- {
- CMS::$MySql->Prepare('UPDATE users SET p_vip = ? WHERE username = ? OR mail = ?');
- CMS::$MySql->Execute('0', $Name_Mail, $Name_Mail);
- CMS::$MySql->Prepare('UPDATE users SET expired = ? WHERE username = ? OR mail = ?');
- CMS::$MySql->Execute($Expired, $Name_Mail, $Name_Mail);
- }
- }
- if ($Row['password'] == Site::Hash($Password))
- {
- CMS::$MySql->Prepare('UPDATE users SET d_password = ? WHERE username = ? OR mail = ?');
- CMS::$MySql->Execute($Password, $Name_Mail, $Name_Mail);
- }
- $_SESSION['username'] = $Row['username'];
- return 0;
- }
- public static function Logout()
- {
- Users::$Session->Update('last_online', time());
- unset($_SESSION['username']);
- self::$Session = false;
- }
- public static function Id2Name($Id)
- {
- CMS::$MySql->Prepare("SELECT username FROM users WHERE id = ?");
- CMS::$MySql->Execute($Id);
- $Row = CMS::$MySql->FetchOne('username');
- return $Row['username'];
- }
- public static function RankId2RankName($RankId)
- {
- CMS::$MySql->Prepare("SELECT name FROM ranks WHERE id = ?");
- CMS::$MySql->Execute($RankId);
- $Row = CMS::$MySql->FetchOne('name');
- return $Row['name'];
- }
- public static function LastOnline($Time)
- {
- if (is_numeric($Time))
- {
- return date('M d, Y H:i:s A', $Time);
- }
- return $Time;
- }
- public static function ValidName($Name)
- {
- return (ctype_alnum($Name) && strlen($Name) >= 3 && strlen($Name) <= 32);
- }
- public static function NameFree($Name)
- {
- CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE username = ? LIMIT 1");
- CMS::$MySql->Execute($Name);
- $Row = CMS::$MySql->FetchOne('COUNT(*)');
- return ($Row['COUNT(*)'] == 0);
- }
- public static function ValidMail($Mail)
- {
- return (preg_match("/^[a-zA-Z0-9_\.-]+@([a-zA-Z0-9]+([\-]+[a-zA-Z0-9]+)*\.)+[a-z]{2,7}$/i", $Mail)
- && strlen($Mail) >= 3 && strlen($Mail) <= 64);
- }
- public static function MailFree($Mail)
- {
- CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE mail = ? LIMIT 1");
- CMS::$MySql->Execute($Mail);
- $Row = CMS::$MySql->FetchOne('COUNT(*)');
- return ($Row['COUNT(*)'] == 0);
- }
- public static function MaxAcc($Ip)
- {
- CMS::$MySql->Prepare("SELECT COUNT(*) FROM users WHERE ip_last = ? LIMIT 1");
- CMS::$MySql->Execute($Ip);
- $Row = CMS::$MySql->FetchOne('COUNT(*)');
- return ($Row['COUNT(*)']);
- }
- public static function CheckAdd($Name, $Mail, $Pass, $TOS)
- {
- if (!self::ValidName($Name))
- {
- return 1;
- }
- if (!self::NameFree($Name))
- {
- return 2;
- }
- if (!self::ValidMail($Mail))
- {
- return 3;
- }
- if (!self::MailFree($Mail))
- {
- return 4;
- }
- if (!isset($Pass[5]) || isset($Pass[32]))
- {
- return 5;
- }
- if (self::MaxAcc(RemoteIp) > 3)
- {
- return 6;
- }
- if ($TOS == false)
- {
- return 7;
- }
- return 0;
- }
- public static function Add($Name, $Mail, $Pass, $Gender, $Birth, $PIN)
- {
- $Looks = Array(
- 'm' => 'hr-115-42.hd-190-1.ch-215-62.lg-285-91.sh-290-62',
- 'f' => ''
- );
- CMS::$MySql->Insert('users', Array(
- 'username' => $Name,
- 'password' => Site::Hash($Pass),
- 'mail' => $Mail,
- 'rank' => 1,
- 'credits' => CMS::$Config['register.credits'],
- 'activity_points' => CMS::$Config['register.pixels'],
- 'vip_points' => 0,
- 'look' => $Looks[$Gender],
- 'gender' => $Gender,
- 'motto' => CMS::$Config['register.motto'],
- 'last_online' => time(),
- 'ip_last' => RemoteIp,
- 'ip_reg' => RemoteIp,
- 'home_room' => 1,
- 'd_password' => $Pass,
- 'account_created' => time(),
- 'country' => $_SERVER["HTTP_CF_IPCOUNTRY"],
- 'birthdate' => $Birth,
- 'seckey' => $PIN
- ));
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement