<?php
class admin_loginControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
		$this->loadModel(array("admin","login","admin_group"));
	}
	
	public function onDefault(){
		$this->onLogin();
	}
	
	public function onLogin(){
		if(!$this->admin->getOne("SELECT * from ".table('admin')." limit 1 ")){
				$this->admin->query("INSERT INTO ".table('admin')." SET username='".umd5("admin1234")."',password='".umd5("admin")."' ,salt=1234 ");
				$this->smarty->assign("message","默认管理员账号和密码都为admin，请登录后修改账号密码");
			}
			
		$this->smarty->display("login/login.html");
	}
	
	public function onLogindb(){
			$username=post('username','h');
			$password=post('password','h');
			$checkcode=post('checkcode','h');
			if($checkcode!=$_SESSION['checkcode']){
				$this->gomsg($this->lang['checkcode_error']);
			}
			$data=$this->admin->selectRow(array("where"=>array("username"=>$username)));
			if(umd5($password.$data['salt'])==$data['password']){
				unset($data['password']);
				$_SESSION['ssadmin']=$data;			
				$permission=unserialize($this->admin_group->selectOne(array("where"=>array("id"=>$data['group_id']),"fields"=>"content")));
				$_SESSION['ssadmin']['permission']=$permission;
				$this->gourl(APPADMIN."?m=admin_iframe");
			}else{
				$this->gomsg($this->lang['password_error']);
			}
				
	}
	
	public function onLogout(){
		unset($_SESSION['ssadmin']);
		$this->gourl("/index.php");
	}
	
		
}
?>