<?php
 /*
 * 74cms ajax返回
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(dirname(__FILE__)).'/include/plus.common.inc.php');
require_once(QISHI_ROOT_PATH.'include/fun_user.php');
$act = !empty($_REQUEST['act']) ? trim($_REQUEST['act']) : '';
if($act =='do_login')
{
	$username=isset($_POST['username'])?trim($_POST['username']):"";
	$password=isset($_POST['password'])?trim($_POST['password']):"";
	$expire=isset($_POST['expire'])?intval($_POST['expire']):"";
	$utype=isset($_POST['utype'])?intval($_POST['utype']):"";
	$account_type=1;
	if (preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$username))
	{
	$account_type=2;
	}
	elseif (preg_match("/^(13|15|18)\d{9}$/",$username))
	{
	$account_type=3;
	}
	$url=isset($_POST['url'])?$_POST['url']:"";
	if ($username && $password)
	{
		$login=user_login($username,$password,$utype,$account_type,true,$expire);
		$url=$url?$url:$login['qs_login'];
		if ($login['qs_login'])
		{
		exit("<script language=\"javascript\" type=\"text/javascript\">window.location.href=\"".$url."\";</script>");
		}
		else
		{
		exit("err");
		}
	}
	exit("err");
}
elseif ($act=='do_reg')
{
	$captcha=get_cache('captcha');
	if ($captcha['verify_userreg']=="1")
	{
		$postcaptcha=$_POST['postcaptcha'];
		if (empty($postcaptcha) || empty($_SESSION['imageCaptcha_content']) || strcasecmp($_SESSION['imageCaptcha_content'],$postcaptcha)!=0)
		{
		exit("err");
		}
	}
	$username = isset($_POST['username'])?trim($_POST['username']):exit("err");
	$password = isset($_POST['password'])?trim($_POST['password']):exit("err");
	$member_type = isset($_POST['utype'])?intval($_POST['utype']):exit("err");
	if($member_type==1)
	{
		$email = isset($_POST['email'])?trim($_POST['email']):exit("err");
	}
	else
	{
		$email = $username;
	}
	$register=user_register($username,$password,$member_type,$email);
	if ($register>0)
	{	
		$login_js=user_login($username,$password);
		$mailconfig=get_cache('mailconfig');
		if ($mailconfig['set_reg']=="1")
		{
		dfopen($_CFG['site_domain'].$_CFG['site_dir']."plus/asyn_mail.php?uid=".$_SESSION['uid']."&key=".asyn_userkey($_SESSION['uid'])."&sendemail=".$email."&sendusername=".$username."&sendpassword=".$password."&act=reg");
		}
		$qsurl=$login_js['qs_login'];
		$qsjs="<script language=\"javascript\" type=\"text/javascript\">window.location.href=\"".$qsurl."\";</script>";
		 if ($qsurl)
			{
			exit($qsjs);
			}
			else
			{
			exit("err");
			}
	}
	else
	{
	exit("err");
	}
}
elseif($act =='check_usname')
{
	$usname=trim($_POST['usname']);
	$user=get_user_inusername($usname);
	empty($user)?exit("true"):exit("false");
}
elseif($act == 'check_reg_usname')
{
	$usname=trim($_POST['param']);
	$user=get_user_inusername($usname);
	empty($user)?exit("y"):exit("该用户名已存在！");
}
elseif($act == 'check_reg_email')
{
	$email=trim($_POST['param']);
	$user=get_user_inemail($email);
	empty($user)?exit("y"):exit("该邮箱已被注册！");
}
elseif($act=="check_reg_verify")
{	
	$code=trim($_POST['param']);
	if ($code == $_SESSION['imageCaptcha_content']) {
		exit("y");
	} else {
		exit("验证码输入错误！");
	}
}
elseif($act == 'check_email')
{
	$email=trim($_POST['email']);
	$user=get_user_inemail($email);
	empty($user)?exit("true"):exit("false");
}
elseif($act=="logout")
{
	setcookie("QS[uid]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
	setcookie("QS[username]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
	setcookie("QS[password]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
	setcookie("QS[utype]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
	unset($_SESSION['uid'],$_SESSION['username'],$_SESSION['parentuid'],$_SESSION['utype'],$_SESSION['uqqid'],$_SESSION['activate_username'],$_SESSION['activate_email'],$_SESSION["openid"]);
    $logoutjs.="<script language=\"javascript\" type=\"text/javascript\">window.location.href=\"".url_rewrite('QS_index')."\";</script>";
	exit($logoutjs);
}
//单独选择的语言是否已经纯在
elseif($act == 'only_check_language'){
		$lang = trim($_POST['param'])?trim($_POST['param']):exit("选择语言不能为空！");
		$sql = "select * from ".table('resume_language')." where language = ".$lang." and uid = ".$_SESSION['uid'];
		$userinfo=$db->getone($sql);
		if ($userinfo)
		{
			exit("已经选择此语言!");
		}else{
			exit("y");
		} 
}
//修改密码判断原密码是否正确
elseif($act == 'check_old_pass')
{
	$opass = $_POST['param']?trim($_POST['param']):exit("请输入旧密码！");
	$user_info=get_user_inid(intval($_SESSION['uid']));
	$opass_md5 = md5(md5($opass).$user_info['pwd_hash'].$QS_pwdhash);
	if($user_info['password']<>$opass_md5)
	{
		exit("原密码输入错误！");
	}
	else
	{
		exit("y");
	}
}
?>