Файл: system/system/classes/dauth.php
Строк: 108
<?defined('SYSPATH') or die('<b>403<br />Запрет доступа</b>');
class DAuth extends Controller
{
protected $sid = null;
protected $uid = null;
public function Login($login,$password)
{
$user = $this->GetUser($login);
if($user==null)
{
return null;
}
if($user['password']!=$password)
{
return null;
}
setcookie('log',$login,time()+60*60*72);
setcookie('pass',$password,time()+60*60*72);
$this->session($user['id']);
$now = date('m.d.y H:i:s');
$this->mysql->update('user',"date_last='$now'","login='$login'");
return true;
}
public function Logout()
{
$sid = $_SESSION['sid'];
$where = "sid = '$sid'";
$this->mysql->delete('session', $where);
session_destroy();
setcookie('log','',time()-60*60*72);
setcookie('pass','',time()-60*60*72);
header('Location:'.URL);
}
public function GetUser($login)
{
if($this->mysql->num_rows('user',"login='$login'",'*'))
{
$user = $this->mysql->arr('user',"login='$login'",'*');
return $user;
}
else
{
return null;
}
}
public function IdUser($id)
{
if($this->mysql->num_rows('user',"id='$id'",'*'))
{
$user = $this->mysql->arr('user',"id='$id'",'*');
return $user;
}
else
{
return null;
}
}
public function session($id)
{
if($this->mysql->num_rows('session',"id_user='$id'")!=null)
{
$this->mysql->delete('session',"id_user='$id'");
}
$sid = gen(15);
$now = date('Y-m-d H:i:s');
$time_start = $now;
$time_last = $now;
$this->mysql->insert('session','id,id_user,sid,time_start,time_last',"'0','$id','$sid','$time_start','$time_last'");
$_SESSION['sid'] = $sid;
return $this->sid = $sid;
}
public function Uid()
{
if ($this->uid != null)
return $this->uid;
$sid = $this->Sid();
if ($sid == null)
{
return null;
}
if($this->mysql->num_rows('session',"sid='$sid'") == false)
{
return null;
}
$result = $this->mysql->arr('session',"sid='$sid'");
$result['id_user'];
$this->uid = $result['id_user'];
return $this->uid;
}
public function Sid()
{
if ($this->sid != null)
return $this->sid;
$sid = $_SESSION['sid'];
if($sid != null)
{
$now = date('Y-m-d H:i:s');
$af=mysql_query("UPDATE `session` SET `time_last`='$now' WHERE `sid`='$sid'");
$uid=$this->mysql->arr('session',"sid='$sid'",'*');
$this->mysql->update('user',"date_last='$now'","id='$uid[id_user]'");
if($af == false)
$sid = null;
}
if($sid == null && isset($_COOKIE['log']))
{
echo '2';
$user = $this->GetUser($_COOKIE['log']);
if ($user != null && $user['password'] == $_COOKIE['pass'])
$sid = $this->session($user['id']);
}
if ($sid != null)
$this->sid = $sid;
return $sid;
}
public function ClSess()
{
$m = date('Y-m-d H:i:s', time() - 300);
$this->mysql->delete('session','time_last < '.$m);
}
public function onLine()
{
$m = date('Y-m-d H:i:s', time() - 300);
$schet=mysql_result(mysql_query("SELECT COUNT(*) from `session` WHERE `time_last`>'$m'"),0);
$sch=mysql_result(mysql_query("SELECT COUNT(*) from `user`"),0);
echo '<a href="'.URL.'cabinet/users.php?type=online">On-line ('.$schet.')</a>|<a href="'.URL.'cabinet/users.php">Юзеры ('.$sch.')</a>';
}
public function admin($level='1')
{
$us=$this->IdUser($this->Uid());
if($us['privileges']!=$level)
{
Errors::__echo("Проваливай отсюда!Эта страница доступна только для админов!");
}
}
public function aut()
{
$id=$this->Uid();
if($id==null)
{
Errors::__echo("Эта страница доступна только админу");
}
}
}