From 3a08bd457f6c04303e3db41dd9ff9411da7afa76 Mon Sep 17 00:00:00 2001 From: akulikov Date: Mon, 27 Apr 2009 19:12:10 +0000 Subject: [PATCH] user git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/legacy@80 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/User.class.php | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 classes/User.class.php diff --git a/classes/User.class.php b/classes/User.class.php new file mode 100644 index 0000000..75093ae --- /dev/null +++ b/classes/User.class.php @@ -0,0 +1,119 @@ +isBanned()) { + return false; + } + + if(self::$user->pass != $password){ + return false; + } + + self::setSession(); + + return true; + } + + static function logout() + { + Env::setCookie(session_name(), '', 0); + Env::setCookie('login', '', 0); + Env::setCookie('login_hash', '', 0); + if (session_id()) { + session_destroy(); + } + } + + static function process() + { + if (Env::getCookie(session_name())) { //есть сессия + @session_start(); + self::setInfo(Env::Session('user')); + } elseif (Env::getCookie('login') && Env::getCookie('login_hash')) { + self::remember(); + } + } + + static function setSession() + { + $hash = self::getHash(); + Env::setCookie('login', self::$user->login, TIME_NOW + LOGIN_COOKIE_TTL); + Env::setCookie('login_hash', $hash, TIME_NOW + LOGIN_COOKIE_TTL); + + @session_start(); + + $_SESSION['user'] = self::$user; + } + + static function remember() + { + self::setInfo(self::getByLogin(Env::getCookie('login'))); + + if (!self::getInfo()) { + self::logout(); + } + + if (Env::getCookie('login_hash') == self::getHash()) { + self::setSession(); + } else { + self::logout(); + } + } + + static function getHash() + { + return md5(self::$user->id.'hckrz'.self::$user->login.'mst'.self::$user->pass.'dai'); + } + + static function getInfo() + { + return Env::Session('user', self::$user); + } + + static function setInfo($data) + { + self::$user = $data; + } + + static function isGuest() + { + return ! (bool) Env::Session('user'); + } + + static function getByLogin($login) + { + $model = new UserDataModel(); + return $model->getByLogin($login); + } + + static function getById($id) + { + $model = new UserDataModel(); + return $model->getById($id); + } +} +?> \ No newline at end of file