Файл: system/classes/User.php
Строк: 67
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
class User
{
private static $id = false; // id of user
public static function logged()
{
global $db;
if(isset($_SESSION['uid']) && isset($_SESSION['password']))
{
$user_id = $_SESSION['uid'];
$user_pass = $_SESSION['password'];
}
elseif(isset($_COOKIE['uid']) && isset($_COOKIE['password']))
{
$user_id = $_COOKIE['uid'];
$user_pass = $_COOKIE['password'];
}
if(isset($user_id) && isset($user_pass))
{
if($db->query("SELECT * FROM `users` WHERE `id` = '". $user_id ."' AND `password` = '". $user_pass ."'")->rowCount() == 1)
{
self::$id = $db->query("SELECT `id` FROM `users` WHERE `id` = '". $user_id ."' AND `password` = '".$user_pass."'")->fetchColumn();
$db->query("UPDATE `users` SET `time` = '". time()."' WHERE `id` = '". $user_id ."'");
}
return true;
}
else
{
return false;
}
}
public static function Id()
{
if(self::logged())
{
return self::$id;
}
else
{
return false;
}
}
public static function pages()
{
if(self::logged())
{
return self::settings('ames');
}
else
{
return Core::config('ames');
}
}
public static function settings($row = '', $userId = null)
{
global $db;
if(self::logged())
{
if($row === '')
{
return $db->query("SELECT * FROM `settings` WHERE `user_id` = '".self::Id()."'")->fetch();
}
else
{
if($userId === null)
{
return $db->query("SELECT `".$row."` FROM `settings` WHERE `user_id` = '".self::Id()."'")->fetchColumn();
}
else
{
return $db->query("SELECT `".$row."` FROM `settings` WHERE `user_id` = '".$userId."'")->fetchColumn();
}
}
}
}
public static function profile($row = '', $userId = null)
{
global $db;
if(self::logged())
{
if($row == '')
{
return $db->query("SELECT * FROM `users` WHERE `id` = '".self::Id()."'")->fetch();
}
else
{
if($userId === null)
{
return $db->query("SELECT `".$row."` FROM `users` WHERE `id` = '".self::Id()."'")->fetchColumn();
}
else
{
return $db->query("SELECT `".$row."` FROM `users` WHERE `id` = '".$userId."'")->fetchColumn();
}
}
}
}
public static function level()
{
if(self::logged())
{
return self::profile('level');
}
else
{
return false;
}
}
}