<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Home\Controller;

use Think\Controller;

/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用分组名称
 */
class HomeController extends Controller {
	
	/* 空操作，用于输出404页面 */
	public function _empty() {
		$this->redirect ( 'Index/index' );
	}
	protected function _initialize() {
		/* 读取站点配置 */
		$config = api ( 'Config/lists' );
		C ( $config ); // 添加配置
		
		if (! C ( 'WEB_SITE_CLOSE' )) {
			$this->error ( '站点已经关闭，请稍后访问~' );
		}
		$this->assign ( "controller", CONTROLLER_NAME );
	}
	
	/* 用户登录检测 */
	protected function login() {
		/* 用户登录检测 */
		is_login () || $this->error ( '您还没有登录，请先登录！', U ( 'User/login' ) );
	}
	
	/**
	 * @abstract 检测用户权限
	 * @return number
	 */
	protected function checkAuth(){
		$domain = $_SERVER['SERVER_NAME'];
		if(!file_exists(realpath(__ROOT__)."\license.lock")){
			return 0;
		}
		$domain = $_SERVER['SERVER_NAME'];
		$myfile = fopen(realpath(__ROOT__)."\license.lock", "r") or die("Unable to open file!");
		$str = fread($myfile,filesize(realpath(__ROOT__)."\license.lock"));
		
		if($str == md5($domain.C("DATA_AUTH_KEY")."1")) return 1;
		if($str == md5($domain.C("DATA_AUTH_KEY")."2")) return 2;
		if($str == md5($domain.C("DATA_AUTH_KEY")."3")) return 3;
		if($str == md5($domain.C("DATA_AUTH_KEY")."4")) return 4;
		if($str == md5($domain.C("DATA_AUTH_KEY")."5")) return 5;
		if($str == md5($domain.C("DATA_AUTH_KEY")."6")) return 6;
		if($str == md5($domain.C("DATA_AUTH_KEY")."7")) return 7;
		
		fclose($myfile);
		return 0;
	}
}
