Файл: tyde/www/application/libraries/Uauth.php
Строк: 25
<?php
class Uauth
{
protected $user = FALSE;
public function __construct ()
{
if (isset($_COOKIE['user_id'], $_COOKIE['sid']))
{
$data = [
0 => (int) $_COOKIE['user_id'],
1 => (string) $_COOKIE['sid']
];
$query = get_instance()->db->query('SELECT * FROM `users` WHERE `id` = ? AND `hash` = ?', $data);
if ($query->num_rows() > 0)
{
$this->user = $query->row_array();
}
}
}
public function get ($offset)
{
return isset($this->user[$offset]) ? $this->user[$offset] : NULL;
}
public function isAuth ()
{
return (bool) $this->user;
}
public function loginById ($id = 0)
{
$query = get_instance()->db->query('SELECT * FROM `users` WHERE `id` = ?', [(int) $id]);
if (!$query->num_rows())
{
return 'Анонимно';
}
else
{
return $query->row_array()['login'];
}
}
}