<?php
class PublicAction extends GlobalAction{
    /**
     * 提交登录
	 *
     */
    public function dologin(){
	
		$username = trim($_POST['username']);
		$password = trim($_POST['password']);
		$verifycode = trim($_POST['verifycode']);
		
        if(empty($username) || empty($password)){
            echo 'emptyInfo';
            exit();
		}
		elseif(md5($verifycode) != Session::get('verify')) {
            echo 'errorVerifyCode';
            exit();
        }
		
        $condition = array();
		$Admin = D('Admin');
        $condition['username'] = $username;
		$result = $Admin->where($condition)->find();

		if(false == $result){
            echo 'usernameFalse';
            exit();
		}
		else{
			if($result['password'] !== adminmymd5($password)){
                echo 'passwordFalse';
				exit();
			}	
			
            Session::set('username',$result['username']);
            Session::set('adminid',$result['id']);
            echo 'loginSuccess';
            exit();
		}	
	}	
	
    /**
     * 退出登录
	 *
     */
	public function logout(){
		
		Session::destroy();
		redirect(U('Index/login'));
	}
	
    /**
     * 验证码
	 *
     */
	public function verify() {
		$type = isset($_GET['type'])?$_GET['type']:'gif';
        import('ORG.Util.Image');
        Image::buildImageVerify(4,1,$type);
    }
}
?>