|
|
@ -2,7 +2,7 @@ |
|
|
|
/** |
|
|
|
* Класс для работы с пользователями |
|
|
|
* |
|
|
|
* @copyright |
|
|
|
* @copyright netmonsters.ru |
|
|
|
* @link |
|
|
|
* @package Majestic |
|
|
|
* @subpackage Decorator |
|
|
@ -12,11 +12,11 @@ |
|
|
|
*/ |
|
|
|
class User |
|
|
|
{ |
|
|
|
static private $user = false; |
|
|
|
static private $user = false; |
|
|
|
|
|
|
|
static function login($login, $password) |
|
|
|
{ |
|
|
|
if (empty($login) || empty($password)) { |
|
|
|
static function login($login, $password) |
|
|
|
{ |
|
|
|
if (empty($login) || empty($password)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@ -25,7 +25,7 @@ class User |
|
|
|
} |
|
|
|
|
|
|
|
self::setInfo(self::getByLogin($login)); |
|
|
|
if (!self::getInfo() || self::$user->isBanned()) { |
|
|
|
if (!self::getInfo()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@ -34,22 +34,19 @@ class User |
|
|
|
} |
|
|
|
|
|
|
|
self::setSession(); |
|
|
|
$model = new UserDataModel(); |
|
|
|
$model->loginUpdate($login); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
static function logout() |
|
|
|
{ |
|
|
|
static function logout() |
|
|
|
{ |
|
|
|
Env::setCookie(session_name(), '', 0); |
|
|
|
Env::setCookie('login', '', 0); |
|
|
|
Env::setCookie('login_hash', '', 0); |
|
|
|
Env::setCookie('login_ipbhash', '', 0); |
|
|
|
if (session_id()) { |
|
|
|
session_destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static function process() |
|
|
|
{ |
|
|
@ -61,106 +58,62 @@ class User |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static function setSession() |
|
|
|
{ |
|
|
|
static function setSession() |
|
|
|
{ |
|
|
|
$hash = self::getHash(); |
|
|
|
Env::setCookie('login', self::$user->login, TIME_NOW + LOGIN_COOKIE_TTL); |
|
|
|
Env::setCookie('login', self::$user->login, TIME_NOW + LOGIN_COOKIE_TTL); |
|
|
|
Env::setCookie('login_hash', $hash, TIME_NOW + LOGIN_COOKIE_TTL); |
|
|
|
Env::setCookie('login_ipbhash', self::getIPBHash($hash), TIME_NOW + LOGIN_COOKIE_TTL); |
|
|
|
|
|
|
|
@session_start(); |
|
|
|
|
|
|
|
$_SESSION['user'] = self::$user; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static function remember() |
|
|
|
{ |
|
|
|
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'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Создает хеш для проверки хеша в в IPB |
|
|
|
* |
|
|
|
*/ |
|
|
|
static public function getIPBHash($hash) |
|
|
|
if (!self::getInfo()) { |
|
|
|
self::logout(); |
|
|
|
} |
|
|
|
|
|
|
|
if (Env::getCookie('login_hash') == self::getHash()) { |
|
|
|
self::setSession(); |
|
|
|
} else { |
|
|
|
self::logout(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static function getHash() |
|
|
|
{ |
|
|
|
return md5($hash . strtolower(self::$user->login) . 'brainfuck'); |
|
|
|
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 getInfo() |
|
|
|
{ |
|
|
|
return Env::Session('user', self::$user); |
|
|
|
} |
|
|
|
|
|
|
|
static function setInfo($data) |
|
|
|
{ |
|
|
|
self::$user = $data; |
|
|
|
} |
|
|
|
|
|
|
|
static function isGuest() |
|
|
|
{ |
|
|
|
return ! (bool) Env::Session('user'); |
|
|
|
} |
|
|
|
static function isGuest() |
|
|
|
{ |
|
|
|
return ! (bool) Env::Session('user'); |
|
|
|
} |
|
|
|
|
|
|
|
static function getByLogin($login) |
|
|
|
{ |
|
|
|
static function getByLogin($login) |
|
|
|
{ |
|
|
|
$model = new UserDataModel(); |
|
|
|
return $model->getByLogin($login); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static function getById($id) |
|
|
|
{ |
|
|
|
$model = new UserDataModel(); |
|
|
|
return $model->getById($id); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* отправляет письмо для активации |
|
|
|
* |
|
|
|
* @param string $mail |
|
|
|
* @param string $login |
|
|
|
* |
|
|
|
*/ |
|
|
|
static function sendActivateMail($mail, $login) |
|
|
|
{ |
|
|
|
$settings = Env::getParam('site_settings'); |
|
|
|
$model = new UserActivateModel(); |
|
|
|
$link = 'http://' . $settings['host_name'] . '/activate/?key=' . $model->generateKey($login, $mail); |
|
|
|
|
|
|
|
$text = new SettingsTextModel(); |
|
|
|
$message = $text->getText('mail_activate'); |
|
|
|
|
|
|
|
$replaces = array( |
|
|
|
'link' => $link, |
|
|
|
'host' => $settings['site_url'], |
|
|
|
'email' => $mail, |
|
|
|
); |
|
|
|
|
|
|
|
if (!$message) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($replaces as $key => $val) { |
|
|
|
$message->text = str_replace('%' . $key . '%', $val, $message->text); |
|
|
|
} |
|
|
|
$mailer = new Mailer(); |
|
|
|
return $mailer->sendMessage($mail, 'Подтверждение E-mail ' . $settings['host_name'], $message->text); |
|
|
|
} |
|
|
|
} |
|
|
|
?>
|
|
|
|
?>
|