<?php
//后台基础控制器
class baseController extends Controller {
    public  $common;

	//构造方法
	public function __construct(){
	    @header('Content-type: text/html;charset=UTF-8');
        $this->common = new Common();
        $this->checkToken();
	    $notLogin = config('system.notlogin');
	    if( !in_array(CONTROLLER, $notLogin))
	    {
	        $this->checkLogin();
	    }

	}
	
	//验证用户是否登录
	public function checkLogin(){
	    //var_dump($_SESSION['admin']);die();
	    //注意，此处的admin是我在登录成功时保存的登录标识符
	    if (!isset($_SESSION['admin'])) {
	        $this->jump("/".ADMIN_NAME.'/login/login','你还没有登录呢');  
	    }
		
	}

    /**
     * 验证后台访问token
     * @date: 2019年5月7日 上午10:01:46
     * @author: 龚华尧
     * @param: variable
     * @return:
     */
    public  function checkToken() {
        //session_destroy();

        //验证ADMIN_TOKEN
        if($this->common->Requert("token")!="")
        {
           
            if($this->common->Requert("token")==$GLOBALS['config_cache']['ADMIN_TOKEN']){
                $this->common->set_seesion("ADMIN_TOKEN", $GLOBALS['config_cache']['ADMIN_TOKEN']);
                //var_dump($this->common->get_seesion("ADMIN_TOKEN")); die();
                
            }else{
                die("token 错误");
            }

        }else{
//             var_dump($this->common->get_seesion("ADMIN_TOKEN"));
//             var_dump($GLOBALS['config_cache']['ADMIN_TOKEN']);
//             die();
            if($this->common->get_seesion("ADMIN_TOKEN")!=""){
                if($this->common->get_seesion("ADMIN_TOKEN")!=$GLOBALS['config_cache']['ADMIN_TOKEN']){
                    die("token已更改，请重新使用正确token访问");
                }

            }else{
                 
                die("请使用正确的路径进行访问");
            }

        }

    }
	
	
	
}