<?php

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

class Auth extends ControllerSession {

    public function get_index($data=array())
    {
        if($this->is_auth())
            $this->redirect('?');
        else{
            $this->_template = 'login/index';
            $this->render($this->_template, array('login'=> (isset($data['login']) ? $data['login'] : ''), 'pass'=> (isset($data['pass']) ? $data['pass'] : '')), array('layout'=>false));
        }
    }
    public function get_out()
    {
        $this->session_destroy();
        $this->redirect('?do=auth');
    }

    public function post_index()
    {
        if($this->is_auth())
            $this->redirect('?');
        else{
            $login = $this->params['post']['login'];
            $pass = $this->params['post']['pass'];
            if($login == \lib\Config::read('login') && $pass==\lib\Config::read('pass'))
            {
                $this->auth($login, $pass);
                $this->redirect('?');
            }else
                $this->get_index(array('login'=>$login, 'pass'=>$pass));
        }

    }

}